Skip to content

Commit

Permalink
10502-dxox: fix message sorting error (both message and case have cre…
Browse files Browse the repository at this point in the history
…atedAt, so our queries for messages needed to specify message.createdAt); remove duplicate upsertPractitionersOnCase; fix broken createTestApplicationContext
  • Loading branch information
Mwindo committed Jan 11, 2025
1 parent 7c332b0 commit adcddd4
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 64 deletions.
1 change: 0 additions & 1 deletion __TODO-10502.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- Can we remove formatWorkItemResult and formatMessageResult? What about formatDocketEntryResult?

- if we use the trigram search, run on the db CREATE EXTENSION IF NOT EXISTS pg_trgm;
- upsertPractitionersOnCase: we have two versions
- Some TODOs are marked with "10502 TODO", so search for this (without the quotes) as needed. (solo, meetup as needed)
- Make sure that report data for case-mapping reports (above) is correct, and make sure indices are added for efficiency as needed for all case-based reports (pair)
- Make sure getCasesMetadataByUserId (previously called getCasesForUser) is working. It relies on processPractitionerMappingEntries streaming things into PractitionerOnCaseTable (pair)
Expand Down
5 changes: 5 additions & 0 deletions shared/src/business/test/createTestApplicationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { formatPendingItem } from '@shared/business/utilities/formatPendingItem'
import { formatPhoneNumber } from '@shared/business/utilities/formatPhoneNumber';
import { generateAndServeDocketEntry } from '@web-api/business/useCaseHelper/service/createChangeItems';
import { generateChangeOfAddressHelper } from '@web-api/business/useCaseHelper/generateChangeOfAddressHelper';
import { generateDocketNumber } from '@web-api/persistence/postgres/cases/generateDocketNumber';
import { generateNoticesForCaseTrialSessionCalendarInteractor } from '@web-api/business/useCases/trialSessions/generateNoticesForCaseTrialSessionCalendarInteractor';
import {
getAddressPhoneDiff,
Expand Down Expand Up @@ -535,6 +536,10 @@ export const createTestApplicationContext = () => {

const mockDocumentClient = createMockDocumentClient();

const mockCreateDocketNumberGenerator = {
createDocketNumber: jest.fn().mockImplementation(generateDocketNumber),
};

const mockBroadcastGateway = {
postMessage: jest.fn(),
};
Expand Down
19 changes: 11 additions & 8 deletions web-api/src/business/useCases/messages/createMessageInteractor.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { Case } from '../../../../../shared/src/business/entities/cases/Case';
import {
Message,
RawMessage,
} from '../../../../../shared/src/business/entities/Message';
import { Case } from '@shared/business/entities/cases/Case';
import { Message, RawMessage } from '@shared/business/entities/Message';
import { NotFoundError, UnauthorizedError } from '@web-api/errors/errors';
import {
ROLE_PERMISSIONS,
isAuthorized,
} from '../../../../../shared/src/authorization/authorizationClientService';
} from '@shared/authorization/authorizationClientService';
import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { createMessage } from '@web-api/persistence/postgres/messages/createMessage';
import { getCaseByDocketNumber } from '@web-api/persistence/postgres/cases/getCaseByDocketNumber';
Expand Down Expand Up @@ -48,11 +45,17 @@ export const createMessageInteractor = async (
throw new UnauthorizedError('Unauthorized');
}

const { caseCaption, status } = await getCaseByDocketNumber({
const associatedCase = await getCaseByDocketNumber({
applicationContext,
docketNumber,
});

if (!associatedCase) {
throw new NotFoundError(`Case ${docketNumber} not found`);
}

const { caseCaption, status } = associatedCase;

const fromUser = await applicationContext
.getPersistenceGateway()
.getUserById({ applicationContext, userId: authorizedUser.userId });
Expand Down
23 changes: 14 additions & 9 deletions web-api/src/business/useCases/messages/replyToMessageInteractor.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { Case } from '../../../../../shared/src/business/entities/cases/Case';
import {
Message,
RawMessage,
} from '../../../../../shared/src/business/entities/Message';
import { Case } from '@shared/business/entities/cases/Case';
import { Message, RawMessage } from '@shared/business/entities/Message';
import { NotFoundError, UnauthorizedError } from '@web-api/errors/errors';
import {
ROLE_PERMISSIONS,
isAuthorized,
} from '../../../../../shared/src/authorization/authorizationClientService';
} from '@shared/authorization/authorizationClientService';
import { ReplyMessageType } from '@web-api/business/useCases/messages/createMessageInteractor';
import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { createMessageAsReply } from '@web-api/persistence/postgres/messages/createMessageAsReply';
import { getCaseByDocketNumber } from '@web-api/persistence/postgres/cases/getCaseByDocketNumber';
Expand All @@ -31,8 +28,16 @@ export const replyToMessage = async (
throw new UnauthorizedError('Unauthorized');
}

const { caseCaption, docketNumberWithSuffix, status } =
await getCaseByDocketNumber({ applicationContext, docketNumber });
const associatedCase = await getCaseByDocketNumber({
applicationContext,
docketNumber,
});

if (!associatedCase) {
throw new NotFoundError(`Case ${docketNumber} not found`);
}

const { caseCaption, docketNumberWithSuffix, status } = associatedCase;

const fromUser = await applicationContext
.getPersistenceGateway()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
formatDateString,
formatNow,
getMonthDayYearInETObj,
} from '../../../../../shared/src/business/utilities/DateHandler';
} from '@shared/business/utilities/DateHandler';
import { getCaseMetadataByDocketNumber } from '@web-api/persistence/postgres/cases/getCaseMetadataByDocketNumber';
import { getDbWriter } from '@web-api/database';
import { getLogger } from '@web-api/utilities/logger/getLogger';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { RawPractitioner } from '@shared/business/entities/Practitioner';
import { getDbWriter } from '@web-api/database';
import { isEmpty } from 'lodash';

export const upsertPractitionersOnCase = async ({
practitionersWithDocketNumber,
}: {
practitionersWithDocketNumber: any; // 10502 TODO
practitionersWithDocketNumber: (RawPractitioner & { docketNumber: string })[];
}): Promise<void> => {
if (isEmpty(practitionersWithDocketNumber)) {
return;
Expand All @@ -15,7 +16,7 @@ export const upsertPractitionersOnCase = async ({
.values(
practitionersWithDocketNumber.map(p => ({
docketNumber: p.docketNumber,
email: p.email,
email: p.email || '',
userId: p.userId,
})),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getCompletedSectionInboxMessages = async ({
.where('m.isCompleted', '=', true)
.where('m.createdAt', '>=', filterDate)
.selectAll()
.select('m.docketNumber')
.select(['m.docketNumber', 'm.createdAt'])
.limit(5000)
.execute(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getCompletedUserInboxMessages = async ({
.where('m.isCompleted', '=', true)
.where('m.completedAt', '>=', filterDate)
.selectAll()
.select('m.docketNumber')
.select(['m.docketNumber', 'm.createdAt'])
.limit(5000)
.execute(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getMessageById = async ({
.leftJoin('dwCase as c', 'c.docketNumber', 'm.docketNumber')
.where('messageId', '=', messageId)
.selectAll()
.select('m.docketNumber')
.select(['m.docketNumber', 'm.createdAt'])
.executeTakeFirst(),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getMessageThreadByParentId = async ({
.leftJoin('dwCase as c', 'c.docketNumber', 'm.docketNumber')
.where('m.parentMessageId', '=', parentMessageId)
.selectAll()
.select('m.docketNumber')
.select(['m.docketNumber', 'm.createdAt'])
.execute(),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getMessagesByDocketNumber = async ({
.leftJoin('dwCase as c', 'c.docketNumber', 'm.docketNumber')
.where('m.docketNumber', '=', docketNumber)
.selectAll()
.select('m.docketNumber')
.select(['m.docketNumber', 'm.createdAt'])
.execute(),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const getSectionInboxMessages = async ({
.where('m.isRepliedTo', '=', false)
.where('m.isCompleted', '=', false)
.selectAll()
.select('m.docketNumber')
.select(['m.docketNumber', 'm.createdAt'])
.limit(5000)
.execute(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getSectionOutboxMessages = async ({
.where('m.fromSection', '=', section)
.where('m.createdAt', '>=', filterDate)
.selectAll()
.select('m.docketNumber')
.select(['m.docketNumber', 'm.createdAt'])
.execute(),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const getUserInboxMessages = async ({
.where('m.isRepliedTo', '=', false)
.where('m.toUserId', '=', userId)
.selectAll()
.select('m.docketNumber')
.select(['m.docketNumber', 'm.createdAt'])
.execute(),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getUserOutboxMessages = async ({
.where('m.fromUserId', '=', userId)
.where('m.createdAt', '>=', filterDate)
.selectAll()
.select('m.docketNumber')
.select(['m.docketNumber', 'm.createdAt'])
.limit(5000)
.execute(),
);
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions web-client/src/presenter/sequences/gotoCaseDetailSequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,8 @@ export const gotoCaseDetailSequence = [
closeMobileMenuAction,
setDefaultCaseDetailTabAction,
setIsPrimaryTabAction,
() => {
console.log('GETTING CASE');
},
getCaseAction,
setCaseAction,
() => {
console.log('SET THE CASE');
},
setDefaultDocketRecordSortAction,
setDefaultEditDocumentEntryPointAction,
runPathForUserRoleAction,
Expand Down

0 comments on commit adcddd4

Please sign in to comment.