From 68aa66f52c854e89b8bacf6969e5334af4e08509 Mon Sep 17 00:00:00 2001 From: Kaitlyn Swann Date: Thu, 5 Dec 2024 15:20:30 -0700 Subject: [PATCH 1/3] 10504-fix-entities --- shared/src/business/entities/Correspondence.ts | 4 ++-- shared/src/business/entities/caseWorksheet/CaseWorksheet.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shared/src/business/entities/Correspondence.ts b/shared/src/business/entities/Correspondence.ts index e4665c01a0f..b54ec8da3ee 100644 --- a/shared/src/business/entities/Correspondence.ts +++ b/shared/src/business/entities/Correspondence.ts @@ -10,7 +10,7 @@ export class Correspondence extends JoiValidationEntity { public filedBy: string; public filingDate: string; public userId: string; - public docketNumber: string; + public docketNumber?: string; // Not optional but required as such to enable migration with dynamoDB constructor(rawProps) { super('Correspondence'); @@ -30,7 +30,7 @@ export class Correspondence extends JoiValidationEntity { .optional() .description('A correspondence document that was archived.'), correspondenceId: JoiValidationConstants.UUID.required(), - docketNumber: JoiValidationConstants.STRING.max(10).required(), + docketNumber: JoiValidationConstants.STRING.max(10).optional(), documentTitle: JoiValidationConstants.STRING.max(500).required(), filedBy: JoiValidationConstants.STRING.max(500).allow('').optional(), filingDate: JoiValidationConstants.ISO_DATE.max('now') diff --git a/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts b/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts index b399231ea8e..96d96f0c682 100644 --- a/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts +++ b/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts @@ -6,7 +6,7 @@ export class CaseWorksheet extends JoiValidationEntity { public finalBriefDueDate?: string; public primaryIssue?: string; public statusOfMatter?: string; - public judgeUserId: string; + public judgeUserId?: string; constructor(rawProps) { super('CaseWorksheet'); @@ -37,7 +37,7 @@ export class CaseWorksheet extends JoiValidationEntity { .messages({ '*': 'Enter a valid due date', }), - judgeUserId: JoiValidationConstants.UUID.required(), + judgeUserId: JoiValidationConstants.UUID.optional(), primaryIssue: JoiValidationConstants.STRING.allow('').optional(), statusOfMatter: JoiValidationConstants.STRING.valid( ...CaseWorksheet.STATUS_OF_MATTER_OPTIONS, From 3968472873fbaa283f691e79ed9a5b5ccdc24ab0 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 12 Dec 2024 14:53:49 -0500 Subject: [PATCH 2/3] getCaseByDocketNumber-dxox-experiment: add more indices --- .../upsertCaseCorrespondences.ts | 2 +- .../migrations/0007-additional-indexes.ts | 60 +++++++++++++++++++ .../0007-init-case-correspondence-indexes.ts | 16 ----- 3 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 web-api/src/persistence/postgres/utils/migrate/migrations/0007-additional-indexes.ts delete mode 100644 web-api/src/persistence/postgres/utils/migrate/migrations/0007-init-case-correspondence-indexes.ts diff --git a/web-api/src/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences.ts b/web-api/src/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences.ts index 7e95d5c091f..ce8e688cea4 100644 --- a/web-api/src/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences.ts +++ b/web-api/src/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences.ts @@ -14,7 +14,7 @@ export const upsertCaseCorrespondences = async ( return { archived: correspondence.archived, correspondenceId: correspondence.correspondenceId, - docketNumber: correspondence.docketNumber, + docketNumber: correspondence.docketNumber!, documentTitle: correspondence.documentTitle, filedBy: correspondence.filedBy, filingDate: calculateDate({ dateString: correspondence.filingDate }), diff --git a/web-api/src/persistence/postgres/utils/migrate/migrations/0007-additional-indexes.ts b/web-api/src/persistence/postgres/utils/migrate/migrations/0007-additional-indexes.ts new file mode 100644 index 00000000000..1167514d818 --- /dev/null +++ b/web-api/src/persistence/postgres/utils/migrate/migrations/0007-additional-indexes.ts @@ -0,0 +1,60 @@ +import { Kysely } from 'kysely'; + +export async function up(db: Kysely): Promise { + await db.schema + .createIndex('idx_caseCorrespondence_docketNumber') + .on('dwCaseCorrespondence') + .column('docketNumber') + .execute(); + + await db.schema + .createIndex('idx_caseDeadline_docketNumber') + .on('dwCaseDeadline') + .column('docketNumber') + .execute(); + + await db.schema + .createIndex('idx_caseDeadline_deadlineDate') + .on('dwCaseDeadline') + .column('deadlineDate') + .execute(); + + await db.schema + .createIndex('idx_caseDeadline_sortableDocketNumber') + .on('dwCaseDeadline') + .column('sortableDocketNumber') + .execute(); + + await db.schema + .createIndex('idx_caseDeadline_associatedJudge') + .on('dwCaseDeadline') + .column('associatedJudge') + .execute(); +} + +export async function down(db: Kysely): Promise { + await db.schema + .dropIndex('idx_caseDeadline_associatedJudge') + .on('dwCaseDeadline') + .execute(); + + await db.schema + .dropIndex('idx_caseDeadline_sortableDocketNumber') + .on('dwCaseDeadline') + .execute(); + + await db.schema + .dropIndex('idx_caseDeadline_deadlineDate') + .on('dwCaseDeadline') + .execute(); + + await db.schema + .dropIndex('idx_caseDeadline_docketNumber') + .on('dwCaseDeadline') + .execute(); + + await db.schema + .dropIndex('idx_caseCorrespondence_docketNumber') + .on('dwCaseCorrespondence') + .execute(); +} diff --git a/web-api/src/persistence/postgres/utils/migrate/migrations/0007-init-case-correspondence-indexes.ts b/web-api/src/persistence/postgres/utils/migrate/migrations/0007-init-case-correspondence-indexes.ts deleted file mode 100644 index 94024d17ee9..00000000000 --- a/web-api/src/persistence/postgres/utils/migrate/migrations/0007-init-case-correspondence-indexes.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Kysely } from 'kysely'; - -export async function up(db: Kysely): Promise { - await db.schema - .createIndex('idx_caseCorrespondence_docketNumber') - .on('dwCaseCorrespondence') - .column('docketNumber') - .execute(); -} - -export async function down(db: Kysely): Promise { - await db.schema - .dropIndex('idx_caseCorrespondence_docketNumber') - .on('dwCaseCorrespondence') - .execute(); -} From 5f478d017ee8b8efdd841180b2cf22173f387c33 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Sat, 25 Jan 2025 23:21:37 -0500 Subject: [PATCH 3/3] 10504-dxox: fix discrepancy between test and staging --- .../cases/getCaseByDocketNumber.test.ts | 48 ++++++++++++------- .../dynamo/cases/getCaseByDocketNumber.ts | 34 +++++++------ 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts index a55143266d5..b6ab19dc99a 100644 --- a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts +++ b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts @@ -1,22 +1,21 @@ -import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; +import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/workitems/mocks.jest'; import { CASE_STATUS_TYPES, ROLES, -} from '../../../../../shared/src/business/entities/EntityConstants'; -import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; +} from '@shared/business/entities/EntityConstants'; +import { applicationContext } from '@shared/business/test/createTestApplicationContext'; import { calculateDate } from '@shared/business/utilities/DateHandler'; -import { caseCorrespondenceEntity } from '@web-api/persistence/postgres/caseCorrespondences/mapper'; import { getCaseByDocketNumber } from './getCaseByDocketNumber'; -import { getCaseCorrespondenceByDocketNumber as getCaseCorrespondenceByDocketNumberMock } from '@web-api/persistence/postgres/caseCorrespondences/getCaseCorrespondenceByDocketNumber'; +import { getCaseByDocketNumberPostgres as getCaseByDocketNumberPostgresMock } from '@web-api/persistence/postgres/cases/getCaseByDocketNumber'; -const getCaseCorrespondenceByDocketNumber = - getCaseCorrespondenceByDocketNumberMock as jest.Mock; +const getCaseByDocketNumberPostgres = + getCaseByDocketNumberPostgresMock as jest.Mock; describe('getCaseByDocketNumber', () => { beforeEach(() => { - (getCaseCorrespondenceByDocketNumber as jest.Mock).mockResolvedValue([]); + getCaseByDocketNumberPostgres.mockResolvedValue([]); }); it('should return data as received from persistence', async () => { @@ -51,19 +50,21 @@ describe('getCaseByDocketNumber', () => { }); it('should return case and its associated data', async () => { - getCaseCorrespondenceByDocketNumber.mockResolvedValue([ - caseCorrespondenceEntity({ + getCaseByDocketNumberPostgres.mockResolvedValue([ + { archived: false, correspondenceId: 'abc-124', + docketNumber: '123-20', filingDate: calculateDate({ dateString: '2024-11-06T21:05:08.191Z' }), - }), - caseCorrespondenceEntity({ + }, + { archived: true, correspondenceId: 'abc-123', + docketNumber: '123-20', filingDate: calculateDate({ dateString: '2024-11-06T21:05:08.191Z', }), - }), + }, ]); applicationContext.getDocumentClient().query.mockResolvedValue({ @@ -118,7 +119,15 @@ describe('getCaseByDocketNumber', () => { }); expect(result).toEqual({ - archivedCorrespondences: [], + archivedCorrespondences: [ + { + archived: true, + correspondenceId: 'abc-123', + docketNumber: '123-20', + entityName: 'Correspondence', + filingDate: '2024-11-06T21:05:08.191Z', + }, + ], archivedDocketEntries: [ { archived: true, @@ -127,12 +136,19 @@ describe('getCaseByDocketNumber', () => { ], associatedJudge: 'Judge Fieri', consolidatedCases: [], - correspondence: [], + correspondence: [ + { + archived: false, + correspondenceId: 'abc-124', + docketNumber: '123-20', + entityName: 'Correspondence', + filingDate: '2024-11-06T21:05:08.191Z', + }, + ], docketEntries: [ { archived: false, docketEntryId: 'abc-124', - workItem: undefined, }, ], docketNumber: '123-20', diff --git a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts index c4737df1efc..ccd7d046958 100644 --- a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts +++ b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts @@ -15,12 +15,12 @@ import { caseCorrespondenceEntity } from '@web-api/persistence/postgres/caseCorr import { getCaseByDocketNumberPostgres } from '@web-api/persistence/postgres/cases/getCaseByDocketNumber'; import { purgeDynamoKeys } from '@web-api/persistence/dynamo/helpers/purgeDynamoKeys'; import { queryFull } from '../../dynamodbClientService'; -import { caseContactAddressSealedFormatter } from '@shared/business/utilities/caseFilter'; -import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; import { workItemEntity } from '@web-api/persistence/postgres/workitems/mapper'; +import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; +import { caseContactAddressSealedFormatter } from '@shared/business/utilities/caseFilter'; // These case items are no longer in dynamoDB -const SK_FILTER_OUT = ['work-item']; +const SK_FILTER_OUT = ['work-item', 'correspondence']; export const getCaseByDocketNumber = async ({ applicationContext, @@ -35,22 +35,20 @@ export const getCaseByDocketNumber = async ({ includeCorrespondenceAndWorkItems?: boolean; user?: UnknownAuthUser; }): Promise => { - const [caseItems] = await Promise.all([ - queryFull({ - ExpressionAttributeNames: { - '#pk': 'pk', - }, - ExpressionAttributeValues: { - ':pk': `case|${docketNumber}`, - }, - KeyConditionExpression: '#pk = :pk', - applicationContext, - }).then(items => - items.filter( - item => !SK_FILTER_OUT.some(prefix => item.sk.startsWith(prefix)), - ), + const caseItems = await queryFull({ + ExpressionAttributeNames: { + '#pk': 'pk', + }, + ExpressionAttributeValues: { + ':pk': `case|${docketNumber}`, + }, + KeyConditionExpression: '#pk = :pk', + applicationContext, + }).then(items => + items.filter( + item => !SK_FILTER_OUT.some(prefix => item.sk.startsWith(prefix)), ), - ]); + ); /* We have roughly three options to get all data associated with a case: