Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions serverless/lib/CaseProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import axios from 'axios';
import { wrapper } from 'axios-cookiejar-support';
import * as cheerio from 'cheerio';

// Version date used to determine whether a cached 'complete' CaseSummary is
// up-to-date or should be re-fetched to align with current schema/logic.
export const CASE_SUMMARY_VERSION_DATE = new Date('2025-10-06T00:00:00Z');

// Type for raw portal JSON data - using `any` is acceptable here since we're dealing with
// dynamic external API responses that we don't control
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -254,13 +258,23 @@ async function processCaseDataRecord(
receiptHandle: string
): Promise<FetchStatus> {
try {
// Check for existing data and skip if already complete
// Check for existing data and skip if already complete with current schema version.
const zipCase = await StorageClient.getCase(caseNumber);
if (zipCase && zipCase.fetchStatus.status === 'complete') {
// Always use the cached data for complete cases
await QueueClient.deleteMessage(receiptHandle, 'data');
console.log(`Case ${caseNumber} already complete; using cached data and deleted queue item`);
return zipCase.fetchStatus;
const lastUpdated = zipCase.lastUpdated ? new Date(zipCase.lastUpdated) : new Date(0);

if (lastUpdated.getTime() >= CASE_SUMMARY_VERSION_DATE.getTime()) {
// Cached summary is new enough for current version - use it
await QueueClient.deleteMessage(receiptHandle, 'data');
console.log(
`Case ${caseNumber} already complete and up-to-date (lastUpdated=${zipCase.lastUpdated}); using cached data`
);
return zipCase.fetchStatus;
}

console.log(
`Case ${caseNumber} lastUpdated (${zipCase.lastUpdated}) is older than version date ${CASE_SUMMARY_VERSION_DATE.toISOString()}; re-fetching case summary`
);
}

// Fetch case summary
Expand Down
20 changes: 12 additions & 8 deletions serverless/lib/CaseSearchProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import axios from 'axios';
import { wrapper } from 'axios-cookiejar-support';
import * as cheerio from 'cheerio';
import UserAgentClient from './UserAgentClient';
import { CASE_SUMMARY_VERSION_DATE } from './CaseProcessor';

// Process API case search requests
export async function processCaseSearchRequest(req: CaseSearchRequest): Promise<CaseSearchResponse> {
Expand Down Expand Up @@ -54,27 +55,30 @@ export async function processCaseSearchRequest(req: CaseSearchRequest): Promise<

switch (status) {
case 'complete':
if (caseSummary) {
// Truly complete - has both ID and summary
console.log(`Case ${caseNumber} is complete with summary, preserving`);
const lastUpdated = results[caseNumber].zipCase.lastUpdated;
if (caseSummary && lastUpdated && new Date(lastUpdated) >= CASE_SUMMARY_VERSION_DATE) {
// Truly complete - has both ID and an up-to-date summary
console.log(`Case ${caseNumber} is complete with up-to-date summary schema, preserving`);
continue;
} else if (caseId) {
// Has ID but missing summary - treat as 'found' and queue for data retrieval
// Has ID but missing summary or summary schema is outdated - treat as 'found' and queue for data retrieval
console.log(
`Case ${caseNumber} has 'complete' status but missing summary, treating as 'found' and queueing for data retrieval`
`Case ${caseNumber} has 'complete' status but ${caseSummary ? 'summary is outdated' : 'missing summary'}; treating as 'found' and queueing for data retrieval`
);

// Update status to 'found' since we need to rebuild the summary
const nowString = new Date().toISOString();

// Update status to 'found', since we need to rebuild the summary
await StorageClient.saveCase({
caseNumber,
caseId,
fetchStatus: { status: 'found' },
lastUpdated: new Date().toISOString(),
lastUpdated: nowString,
});

// Also update the results object that will be returned to frontend
results[caseNumber].zipCase.fetchStatus = { status: 'found' };
results[caseNumber].zipCase.lastUpdated = new Date().toISOString();
results[caseNumber].zipCase.lastUpdated = nowString;

try {
await QueueClient.queueCaseForDataRetrieval(caseNumber, caseId, req.userId);
Expand Down