Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10504: Move Case Deadlines, Correspondence, and Case Worksheets to Postgres #10530

Closed
Closed
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
10 changes: 3 additions & 7 deletions shared/src/business/entities/CaseDeadline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Case } from './cases/Case';
import { JoiValidationConstants } from './JoiValidationConstants';
import { JoiValidationEntity } from '@shared/business/entities/JoiValidationEntity';
import { createISODateString } from '../utilities/DateHandler';
import { getUniqueId } from '@shared/sharedAppContext';
import joi from 'joi';
export class CaseDeadline extends JoiValidationEntity {
public associatedJudge: string;
Expand All @@ -15,17 +16,12 @@ export class CaseDeadline extends JoiValidationEntity {
public leadDocketNumber?: string;
public sortableDocketNumber: number;

constructor(rawProps, { applicationContext }) {
constructor(rawProps) {
super('CaseDeadline');

if (!applicationContext) {
throw new TypeError('applicationContext must be defined');
}

this.associatedJudge = rawProps.associatedJudge;
this.associatedJudgeId = rawProps.associatedJudgeId;
this.caseDeadlineId =
rawProps.caseDeadlineId || applicationContext.getUniqueId();
this.caseDeadlineId = rawProps.caseDeadlineId || getUniqueId();
this.createdAt = rawProps.createdAt || createISODateString();
this.deadlineDate = rawProps.deadlineDate;
this.description = rawProps.description;
Expand Down
26 changes: 10 additions & 16 deletions shared/src/business/useCases/getCaseDeadlinesInteractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isAuthorized,
} from '../../authorization/authorizationClientService';
import { UnauthorizedError } from '@web-api/errors/errors';
import { getCaseDeadlinesByDateRange } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange';
import { pick } from 'lodash';

export const getCaseDeadlinesInteractor = async (
Expand All @@ -32,23 +33,16 @@ export const getCaseDeadlinesInteractor = async (
throw new UnauthorizedError('Unauthorized');
}

const { foundDeadlines, totalCount } = await applicationContext
.getPersistenceGateway()
.getCaseDeadlinesByDateRange({
applicationContext,
endDate,
from,
judge,
pageSize,
startDate,
});
const { foundDeadlines, totalCount } = await getCaseDeadlinesByDateRange({
endDate,
from,
judge,
pageSize,
startDate,
});

const validatedCaseDeadlines = CaseDeadline.validateRawCollection(
foundDeadlines,
{
applicationContext,
},
);
const validatedCaseDeadlines =
CaseDeadline.validateRawCollection(foundDeadlines);

const caseMap = await getCasesByDocketNumbers({
applicationContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { autoGenerateDeadline } from './autoGenerateDeadline';
describe('autoGenerateDeadline', () => {
it('should create a case deadline', async () => {
await autoGenerateDeadline({
applicationContext,
deadlineDate: '2019-03-01T21:42:29.073Z',
description: 'Time is a created thing.',
subjectCaseEntity: {
Expand Down
34 changes: 10 additions & 24 deletions web-api/src/business/useCaseHelper/autoGenerateDeadline.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
import { CaseDeadline } from '../../../../shared/src/business/entities/CaseDeadline';
import { createCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline';

/**
* autoGenerateDeadline
*
* @param {object} applicationContext the application context
* @param {string} providers.deadlineDate the date of the deadline to generated
* @param {string} providers.description the description of the deadline
* @param {Case} providers.subjectCaseEntity the subjectCaseEntity
*/
export const autoGenerateDeadline = async ({
applicationContext,
deadlineDate,
description,
subjectCaseEntity,
}) => {
const newCaseDeadline = new CaseDeadline(
{
associatedJudge: subjectCaseEntity.associatedJudge,
associatedJudgeId: subjectCaseEntity.associatedJudgeId,
deadlineDate,
description,
docketNumber: subjectCaseEntity.docketNumber,
sortableDocketNumber: subjectCaseEntity.sortableDocketNumber,
},
{
applicationContext,
},
);
const newCaseDeadline = new CaseDeadline({
associatedJudge: subjectCaseEntity.associatedJudge,
associatedJudgeId: subjectCaseEntity.associatedJudgeId,
deadlineDate,
description,
docketNumber: subjectCaseEntity.docketNumber,
sortableDocketNumber: subjectCaseEntity.sortableDocketNumber,
});

await applicationContext.getPersistenceGateway().createCaseDeadline({
applicationContext,
await createCaseDeadline({
caseDeadline: newCaseDeadline.validate().toRawObject(),
});
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber';

/**
* updateCaseAutomaticBlock
*
Expand All @@ -13,12 +15,9 @@ export const updateCaseAutomaticBlock = async ({
if (caseEntity.trialDate || caseEntity.highPriority) {
return caseEntity;
}
const caseDeadlines = await applicationContext
.getPersistenceGateway()
.getCaseDeadlinesByDocketNumber({
applicationContext,
docketNumber: caseEntity.docketNumber,
});
const caseDeadlines = await getCaseDeadlinesByDocketNumber({
docketNumber: caseEntity.docketNumber,
});

caseEntity.updateAutomaticBlocked({ caseDeadlines });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { PrivatePractitioner } from '../../../../../shared/src/business/entities
import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { WorkItem } from '../../../../../shared/src/business/entities/WorkItem';
import { createCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline';
import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber';
import { getMessagesByDocketNumber } from '@web-api/persistence/postgres/messages/getMessagesByDocketNumber';
import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence';
import { updateMessage } from '@web-api/persistence/postgres/messages/updateMessage';
import { upsertCase } from '@web-api/persistence/postgres/cases/upsertCase';
import diff from 'diff-arrays-of-objects';
Expand Down Expand Up @@ -120,6 +123,7 @@ const updateCaseMessages = async ({
* @returns {Array<function>} the persistence functions required to complete this action
*/
const updateCorrespondence = ({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
applicationContext,
caseToUpdate,
oldCase,
Expand Down Expand Up @@ -149,13 +153,10 @@ const updateCorrespondence = ({
return validCorrespondence.map(
correspondence =>
function updateCorrespondence_cb() {
return applicationContext
.getPersistenceGateway()
.updateCaseCorrespondence({
applicationContext,
correspondence,
docketNumber: caseToUpdate.docketNumber,
});
return updateCaseCorrespondence({
correspondence,
docketNumber: caseToUpdate.docketNumber,
});
},
);
};
Expand Down Expand Up @@ -382,43 +383,30 @@ const updateCaseWorkItems = async ({
);
};

/**
* Identifies user case mappings which require updates and issues persistence calls
* @param {object} args the arguments for updating the case
* @param {object} args.applicationContext the application context
* @param {object} args.caseToUpdate the case with its updated document data
* @param {object} args.oldCase the case as it is currently stored in persistence, prior to these changes
* @returns {Array<function>} the persistence functions required to complete this action
*/
const updateCaseDeadlines = async ({
applicationContext,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
applicationContext, // cannot remove till remaining RELATED_CASE_OPERATIONS functions no longer use applicationContext
caseToUpdate,
oldCase,
}) => {
if (oldCase.associatedJudge === caseToUpdate.associatedJudge) {
return [];
}

const deadlines = await applicationContext
.getPersistenceGateway()
.getCaseDeadlinesByDocketNumber({
applicationContext,
docketNumber: caseToUpdate.docketNumber,
});
const deadlines = await getCaseDeadlinesByDocketNumber({
docketNumber: caseToUpdate.docketNumber,
});

deadlines.forEach(caseDeadline => {
caseDeadline.associatedJudge = caseToUpdate.associatedJudge;
caseDeadline.associatedJudgeId = caseToUpdate.associatedJudgeId;
});
const validCaseDeadlines = CaseDeadline.validateRawCollection(deadlines, {
applicationContext,
});
const validCaseDeadlines = CaseDeadline.validateRawCollection(deadlines);

return validCaseDeadlines.map(
caseDeadline =>
function updateCaseDeadlines_cb() {
return applicationContext.getPersistenceGateway().createCaseDeadline({
applicationContext,
return createCaseDeadline({
caseDeadline,
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { createCaseDeadline as createDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline';
import { withLocking } from '@web-api/business/useCaseHelper/acquireLock';

export const createCaseDeadline = async (
Expand All @@ -26,19 +27,13 @@ export const createCaseDeadline = async (
});
let caseEntity = new Case(caseDetail, { authorizedUser });

const newCaseDeadline = new CaseDeadline(
{
...caseDeadline,
associatedJudge: caseEntity.associatedJudge,
associatedJudgeId: caseEntity.associatedJudgeId,
},
{
applicationContext,
},
);
const newCaseDeadline = new CaseDeadline({
...caseDeadline,
associatedJudge: caseEntity.associatedJudge,
associatedJudgeId: caseEntity.associatedJudgeId,
});

await applicationContext.getPersistenceGateway().createCaseDeadline({
applicationContext,
await createDeadline({
caseDeadline: newCaseDeadline.validate().toRawObject(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { deleteCaseDeadline as deleteDeadline } from '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline';
import { withLocking } from '@web-api/business/useCaseHelper/acquireLock';

export const deleteCaseDeadline = async (
Expand All @@ -26,10 +27,8 @@ export const deleteCaseDeadline = async (

let updatedCase = new Case(caseToUpdate, { authorizedUser });

await applicationContext.getPersistenceGateway().deleteCaseDeadline({
applicationContext,
await deleteDeadline({
caseDeadlineId,
docketNumber,
});

updatedCase = await applicationContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import { CaseDeadline } from '../../../../../shared/src/business/entities/CaseDeadline';
import { ServerApplicationContext } from '@web-api/applicationContext';
import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber';

/**
* getCaseDeadlinesForCaseInteractor
*
* @param {object} applicationContext the application context
* @param {object} providers the providers object
* @param {string} providers.docketNumber the docket number of the case to get case deadlines for
* @returns {Promise} the promise of the getCaseDeadlines call
*/
export const getCaseDeadlinesForCaseInteractor = async (
applicationContext: ServerApplicationContext,
{ docketNumber }: { docketNumber: string },
) => {
const caseDeadlines = await applicationContext
.getPersistenceGateway()
.getCaseDeadlinesByDocketNumber({
applicationContext,
docketNumber,
});

return CaseDeadline.validateRawCollection(caseDeadlines, {
applicationContext,
export const getCaseDeadlinesForCaseInteractor = async ({
docketNumber,
}: {
docketNumber: string;
}) => {
const caseDeadlines = await getCaseDeadlinesByDocketNumber({
docketNumber,
});

return CaseDeadline.validateRawCollection(caseDeadlines);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,28 @@ import {
ROLE_PERMISSIONS,
isAuthorized,
} from '../../../../../shared/src/authorization/authorizationClientService';
import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { createCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline';
import { deleteCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline';

export const updateCaseDeadlineInteractor = async (
applicationContext: ServerApplicationContext,
{ caseDeadline }: { caseDeadline: CaseDeadline },
authorizedUser: UnknownAuthUser,
) => {
if (!isAuthorized(authorizedUser, ROLE_PERMISSIONS.CASE_DEADLINE)) {
throw new UnauthorizedError('Unauthorized for updating case deadline');
}

const caseDeadlineToUpdate = new CaseDeadline(caseDeadline, {
applicationContext,
})
const caseDeadlineToUpdate = new CaseDeadline(caseDeadline)
.validate()
.toRawObject();

await applicationContext.getPersistenceGateway().deleteCaseDeadline({
applicationContext,
await deleteCaseDeadline({
caseDeadlineId: caseDeadlineToUpdate.caseDeadlineId,
docketNumber: caseDeadlineToUpdate.docketNumber,
});

await applicationContext.getPersistenceGateway().createCaseDeadline({
applicationContext,
await createCaseDeadline({
caseDeadline: caseDeadlineToUpdate,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { updateCaseWorksheet } from '@web-api/persistence/postgres/caseWorksheet/updateCaseWorksheet';

export const updateCaseWorksheetInteractor = async (
applicationContext: ServerApplicationContext,
Expand All @@ -31,8 +32,7 @@ export const updateCaseWorksheetInteractor = async (

const rawCaseWorksheet = caseWorksheetEntity.toRawObject();

await applicationContext.getPersistenceGateway().updateCaseWorksheet({
applicationContext,
await updateCaseWorksheet({
caseWorksheet: rawCaseWorksheet,
judgeUserId: judgeUser.userId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence';
import { withLocking } from '@web-api/business/useCaseHelper/acquireLock';

export const archiveCorrespondenceDocument = async (
Expand Down Expand Up @@ -36,8 +37,7 @@ export const archiveCorrespondenceDocument = async (

caseEntity.archiveCorrespondence(correspondenceToArchiveEntity);

await applicationContext.getPersistenceGateway().updateCaseCorrespondence({
applicationContext,
await updateCaseCorrespondence({
correspondence: correspondenceToArchiveEntity.validate().toRawObject(),
docketNumber,
});
Expand Down
Loading
Loading