From 70a31485d378afc350f0c9b1ee759fe429d54f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Thu, 24 Oct 2024 22:10:41 +0000 Subject: [PATCH] fix(j-s): Subpoena Notifications (#16556) * Rewrites subpoena notifications * Fixes type * Updates unit tests * Fixes typo * Fixes required argument * Changes error logging * Update apps/judicial-system/backend/src/app/modules/notification/internalNotification.controller.ts Fixes typo Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: unakb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../src/app/modules/file/file.controller.ts | 42 ++-- .../backend/src/app/formatters/subpoenaPdf.ts | 2 +- .../backend/src/app/messages/courtUpload.ts | 2 +- .../backend/src/app/messages/pdfCore.ts | 3 +- .../src/app/modules/case/case.service.ts | 30 +-- .../modules/case/limitedAccessCase.service.ts | 8 +- .../getRulingSignatureConfirmation.spec.ts | 8 +- .../test/caseController/transition.spec.ts | 30 +-- .../case/test/caseController/update.spec.ts | 10 +- .../deliverConclusionToCourtOfAppeals.spec.ts | 7 +- .../transition.spec.ts | 6 +- .../update.spec.ts | 4 +- .../modules/defendant/defendant.service.ts | 5 +- .../test/defendantController/delete.spec.ts | 4 +- .../test/defendantController/update.spec.ts | 4 +- .../deliverDefendantToCourt.spec.ts | 4 +- .../notification/baseNotification.service.ts | 9 +- ...service.ts => caseNotification.service.ts} | 168 ++++++++------- .../notification/dto/caseNotification.dto.ts | 8 +- .../dto/institutionNotification.dto.ts | 8 +- .../notification/dto/notification.dto.ts | 8 +- .../dto/notificationDispatch.dto.ts | 12 ++ .../dto/subpoenaNotification.dto.ts | 14 +- .../modules/notification/guards/rolesRules.ts | 35 +-- .../institutionNotification.service.ts | 14 +- .../internalNotification.controller.ts | 62 +++--- .../notification/notification.module.ts | 4 +- .../notification/notification.service.ts | 25 ++- .../notificationDispatch.service.ts | 13 +- .../subpoenaNotification.service.ts | 199 ++++++++---------- .../test/createTestingNotificationModule.ts | 4 +- ...aitingForConfirmationNotifications.spec.ts | 13 +- .../sendAdvocateAssignedNotifications.spec.ts | 4 +- .../sendAppealCompletedNotifications.spec.ts | 4 +- ...endAppealFilesUpdatedNotifications.spec.ts | 4 +- ...dAppealJudgesAssignedNotifications.spec.ts | 4 +- ...AppealReceivedByCourtNotifications.spec.ts | 4 +- .../sendAppealStatementNotifications.spec.ts | 4 +- ...ppealToCourtOfAppealsNotifications.spec.ts | 4 +- .../sendAppealWithdrawnNotifications.spec.ts | 6 +- .../sendCaseFilesUpdatedNotifications.spec.ts | 4 +- .../sendCourtDateNotifications.spec.ts | 10 +- ...antsNotUpdatedAtCourtNotifications.spec.ts | 6 +- .../sendHeadsUpNotifications.spec.ts | 4 +- .../sendIndictmentDeniedNotifications.spec.ts | 4 +- ...endIndictmentReturnedNotifications.spec.ts | 4 +- ...aitingForConfirmationNotifications.spec.ts | 4 +- .../sendReadyForCourtNotifications.spec.ts | 14 +- .../sendRevokedNotifications.spec.ts | 8 +- .../sendRulingNotifications.spec.ts | 4 +- .../sendAdvocateAssignedNotifications.spec.ts | 6 +- ...sendAppealFilesUpdatedNotification.spec.ts | 6 +- ...ndAppealJudgesAssignedNotification.spec.ts | 6 +- .../sendCaseFilesUpdatedNotifications.spec.ts | 6 +- .../sendCourtDateNotification.spec.ts | 8 +- .../sendHeadsUpNotifications.spec.ts | 6 +- .../sendReadyForCourtNotifications.spec.ts | 8 +- .../backend/src/app/modules/subpoena/index.ts | 1 + .../modules/subpoena/subpoena.controller.ts | 23 +- .../app/modules/subpoena/subpoena.service.ts | 139 +++++++----- .../getSubpoenaPdfGuards.spec.ts | 19 ++ .../subpoenaControllerGuards.spec.ts | 6 +- .../src/app/test/handleMessage.spec.ts | 2 +- .../scheduler/src/app/app.service.ts | 6 +- .../FormProvider/limitedAccessCase.graphql | 7 + .../Court/Indictments/Overview/Overview.tsx | 4 +- .../Court/Indictments/Subpoena/Subpoena.tsx | 4 +- .../Indictments/Overview/Overview.tsx | 4 +- .../auth/src/lib/guards/roles.guard.ts | 1 + .../message/src/lib/message.ts | 2 + libs/judicial-system/types/src/index.ts | 8 +- .../types/src/lib/notification.ts | 39 +++- 72 files changed, 643 insertions(+), 529 deletions(-) rename apps/judicial-system/backend/src/app/modules/notification/{internalNotification.service.ts => caseNotification.service.ts} (94%) create mode 100644 apps/judicial-system/backend/src/app/modules/notification/dto/notificationDispatch.dto.ts create mode 100644 apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdfGuards.spec.ts diff --git a/apps/judicial-system/api/src/app/modules/file/file.controller.ts b/apps/judicial-system/api/src/app/modules/file/file.controller.ts index 968d52a64cd3..a729124f5f6e 100644 --- a/apps/judicial-system/api/src/app/modules/file/file.controller.ts +++ b/apps/judicial-system/api/src/app/modules/file/file.controller.ts @@ -177,60 +177,60 @@ export class FileController { ) } - @Get('serviceCertificate/:defendantId/:subpoenaId') + @Get(['subpoena/:defendantId', 'subpoena/:defendantId/:subpoenaId']) @Header('Content-Type', 'application/pdf') - getServiceCertificatePdf( + getSubpoenaPdf( @Param('id') id: string, @Param('defendantId') defendantId: string, @CurrentHttpUser() user: User, @Req() req: Request, @Res() res: Response, @Param('subpoenaId') subpoenaId?: string, + @Query('arraignmentDate') arraignmentDate?: string, + @Query('location') location?: string, + @Query('subpoenaType') subpoenaType?: SubpoenaType, ): Promise { this.logger.debug( - `Getting service certificate for defendant ${defendantId} of case ${id} as a pdf document`, + `Getting subpoena ${ + subpoenaId ?? 'draft' + } for defendant ${defendantId} of case ${id} as a pdf document`, ) + const subpoenaIdInjection = subpoenaId ? `/${subpoenaId}` : '' + const queryInjection = arraignmentDate + ? `?arraignmentDate=${arraignmentDate}&location=${location}&subpoenaType=${subpoenaType}` + : '' + return this.fileService.tryGetFile( user.id, - AuditedAction.GET_SERVICE_CERTIFICATE_PDF, + AuditedAction.GET_SUBPOENA_PDF, id, - `defendant/${defendantId}/subpoena/${subpoenaId}/serviceCertificate`, + `defendant/${defendantId}/subpoena${subpoenaIdInjection}${queryInjection}`, req, res, 'pdf', ) } - @Get('subpoena/:defendantId') + @Get('serviceCertificate/:defendantId/:subpoenaId') @Header('Content-Type', 'application/pdf') - getSubpoenaPdf( + getServiceCertificatePdf( @Param('id') id: string, @Param('defendantId') defendantId: string, + @Param('subpoenaId') subpoenaId: string, @CurrentHttpUser() user: User, @Req() req: Request, @Res() res: Response, - @Param('subpoenaId') subpoenaId?: string, - @Query('arraignmentDate') arraignmentDate?: string, - @Query('location') location?: string, - @Query('subpoenaType') subpoenaType?: SubpoenaType, ): Promise { this.logger.debug( - `Getting subpoena ${ - subpoenaId ?? 'draft' - } for defendant ${defendantId} of case ${id} as a pdf document`, + `Getting service certificate for subpoena ${subpoenaId} of defendant ${defendantId} and case ${id} as a pdf document`, ) - const subpoenaIdInjection = subpoenaId ? `/${subpoenaId}` : '' - const queryInjection = arraignmentDate - ? `?arraignmentDate=${arraignmentDate}&location=${location}&subpoenaType=${subpoenaType}` - : '' - return this.fileService.tryGetFile( user.id, - AuditedAction.GET_SUBPOENA_PDF, + AuditedAction.GET_SERVICE_CERTIFICATE_PDF, id, - `defendant/${defendantId}/subpoena${subpoenaIdInjection}${queryInjection}`, + `defendant/${defendantId}/subpoena/${subpoenaId}/serviceCertificate`, req, res, 'pdf', diff --git a/apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts b/apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts index 0088746d840c..58c6fb4bd887 100644 --- a/apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts +++ b/apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts @@ -1,5 +1,5 @@ import PDFDocument from 'pdfkit' -import { MessageDescriptor } from 'react-intl' +import { MessageDescriptor } from '@formatjs/intl' import { FormatMessage } from '@island.is/cms-translations' diff --git a/apps/judicial-system/backend/src/app/messages/courtUpload.ts b/apps/judicial-system/backend/src/app/messages/courtUpload.ts index 060c9cd8cb05..93a9e9c70136 100644 --- a/apps/judicial-system/backend/src/app/messages/courtUpload.ts +++ b/apps/judicial-system/backend/src/app/messages/courtUpload.ts @@ -1,4 +1,4 @@ -import { defineMessages } from 'react-intl' +import { defineMessages } from '@formatjs/intl' export const courtUpload = defineMessages({ request: { diff --git a/apps/judicial-system/backend/src/app/messages/pdfCore.ts b/apps/judicial-system/backend/src/app/messages/pdfCore.ts index 4953071b4eab..83f66d7cb60c 100644 --- a/apps/judicial-system/backend/src/app/messages/pdfCore.ts +++ b/apps/judicial-system/backend/src/app/messages/pdfCore.ts @@ -1,5 +1,4 @@ -import { defineMessage } from 'react-intl' -import { defineMessages } from '@formatjs/intl' +import { defineMessage, defineMessages } from '@formatjs/intl' export const core = { and: defineMessage({ diff --git a/apps/judicial-system/backend/src/app/modules/case/case.service.ts b/apps/judicial-system/backend/src/app/modules/case/case.service.ts index b0bc11dd858f..a3e20ea9f76a 100644 --- a/apps/judicial-system/backend/src/app/modules/case/case.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/case.service.ts @@ -33,6 +33,7 @@ import { CaseFileCategory, CaseFileState, CaseIndictmentRulingDecision, + CaseNotificationType, CaseOrigin, CaseState, CaseTransition, @@ -43,7 +44,6 @@ import { isIndictmentCase, isRequestCase, isTrafficViolationCase, - NotificationType, StringType, UserRole, } from '@island.is/judicial-system/types' @@ -629,7 +629,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.READY_FOR_COURT }, + body: { type: CaseNotificationType.READY_FOR_COURT }, }, ]) } @@ -643,7 +643,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.RECEIVED_BY_COURT }, + body: { type: CaseNotificationType.RECEIVED_BY_COURT }, }, ] @@ -805,7 +805,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.RULING }, + body: { type: CaseNotificationType.RULING }, }, ] @@ -876,7 +876,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.RULING }, + body: { type: CaseNotificationType.RULING }, }, ] @@ -900,7 +900,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.MODIFIED }, + body: { type: CaseNotificationType.MODIFIED }, }, ] @@ -921,7 +921,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.REVOKED }, + body: { type: CaseNotificationType.REVOKED }, }, ] } @@ -987,7 +987,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.APPEAL_TO_COURT_OF_APPEALS }, + body: { type: CaseNotificationType.APPEAL_TO_COURT_OF_APPEALS }, }) return this.messageService.sendMessagesToQueue(messages) @@ -1002,7 +1002,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.APPEAL_RECEIVED_BY_COURT }, + body: { type: CaseNotificationType.APPEAL_RECEIVED_BY_COURT }, }, ]) } @@ -1031,7 +1031,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.APPEAL_COMPLETED }, + body: { type: CaseNotificationType.APPEAL_COMPLETED }, }, { type: MessageType.DELIVERY_TO_COURT_OF_APPEALS_CONCLUSION, @@ -1063,7 +1063,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.APPEAL_STATEMENT }, + body: { type: CaseNotificationType.APPEAL_STATEMENT }, }, ]) } @@ -1077,7 +1077,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.APPEAL_WITHDRAWN }, + body: { type: CaseNotificationType.APPEAL_WITHDRAWN }, }, ]) } @@ -1091,7 +1091,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.INDICTMENT_DENIED }, + body: { type: CaseNotificationType.INDICTMENT_DENIED }, }, ]) } @@ -1105,7 +1105,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.INDICTMENT_RETURNED }, + body: { type: CaseNotificationType.INDICTMENT_RETURNED }, }, ]) } @@ -1168,7 +1168,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.COURT_DATE }, + body: { type: CaseNotificationType.COURT_DATE }, }, ]) } diff --git a/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts b/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts index e31beb4454e5..c21a354ee45c 100644 --- a/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts @@ -20,10 +20,10 @@ import { CaseAppealState, CaseFileCategory, CaseFileState, + CaseNotificationType, CaseState, DateType, EventType, - NotificationType, StringType, UserRole, } from '@island.is/judicial-system/types' @@ -358,7 +358,7 @@ export class LimitedAccessCaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.APPEAL_TO_COURT_OF_APPEALS }, + body: { type: CaseNotificationType.APPEAL_TO_COURT_OF_APPEALS }, }) } @@ -367,7 +367,7 @@ export class LimitedAccessCaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.APPEAL_WITHDRAWN }, + body: { type: CaseNotificationType.APPEAL_WITHDRAWN }, }) } @@ -382,7 +382,7 @@ export class LimitedAccessCaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.APPEAL_STATEMENT }, + body: { type: CaseNotificationType.APPEAL_STATEMENT }, }) } diff --git a/apps/judicial-system/backend/src/app/modules/case/test/caseController/getRulingSignatureConfirmation.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/caseController/getRulingSignatureConfirmation.spec.ts index 25a9fa28deeb..fb99a789abc2 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/caseController/getRulingSignatureConfirmation.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/caseController/getRulingSignatureConfirmation.spec.ts @@ -4,8 +4,8 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' import { CaseFileState, + CaseNotificationType, CaseOrigin, - NotificationType, User, } from '@island.is/judicial-system/types' @@ -136,7 +136,7 @@ describe('CaseController - Get ruling signature confirmation', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.RULING }, + body: { type: CaseNotificationType.RULING }, }, ]) expect(then.result).toEqual({ documentSigned: true }) @@ -172,7 +172,7 @@ describe('CaseController - Get ruling signature confirmation', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.RULING }, + body: { type: CaseNotificationType.RULING }, }, { type: MessageType.DELIVERY_TO_POLICE_SIGNED_RULING, user, caseId }, ]) @@ -204,7 +204,7 @@ describe('CaseController - Get ruling signature confirmation', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.RULING }, + body: { type: CaseNotificationType.RULING }, }, { type: MessageType.DELIVERY_TO_POLICE_SIGNED_RULING, user, caseId }, ]) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/caseController/transition.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/caseController/transition.spec.ts index 08207e2dad15..244783bcaaf2 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/caseController/transition.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/caseController/transition.spec.ts @@ -10,6 +10,7 @@ import { CaseAppealState, CaseFileCategory, CaseFileState, + CaseNotificationType, CaseOrigin, CaseState, CaseTransition, @@ -18,7 +19,6 @@ import { indictmentCases, investigationCases, isIndictmentCase, - NotificationType, restrictionCases, User, } from '@island.is/judicial-system/types' @@ -243,7 +243,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.REVOKED }, + body: { type: CaseNotificationType.REVOKED }, }, ]) } else if ( @@ -260,7 +260,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.RECEIVED_BY_COURT }, + body: { type: CaseNotificationType.RECEIVED_BY_COURT }, }, ]) } else { @@ -384,7 +384,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.RULING }, + body: { type: CaseNotificationType.RULING }, }, { type: MessageType.DELIVERY_TO_POLICE_INDICTMENT_CASE, @@ -409,7 +409,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.REVOKED }, + body: { type: CaseNotificationType.REVOKED }, }, ], ) @@ -423,7 +423,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.READY_FOR_COURT }, + body: { type: CaseNotificationType.READY_FOR_COURT }, }, ], ) @@ -440,7 +440,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.RECEIVED_BY_COURT }, + body: { type: CaseNotificationType.RECEIVED_BY_COURT }, }, { type: MessageType.DELIVERY_TO_COURT_INDICTMENT_INFO, @@ -482,7 +482,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.INDICTMENT_RETURNED }, + body: { type: CaseNotificationType.INDICTMENT_RETURNED }, }, ], ) @@ -499,7 +499,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.INDICTMENT_DENIED }, + body: { type: CaseNotificationType.INDICTMENT_DENIED }, }, ], ) @@ -516,7 +516,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.REVOKED }, + body: { type: CaseNotificationType.REVOKED }, }, ], ) @@ -677,7 +677,9 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.APPEAL_TO_COURT_OF_APPEALS }, + body: { + type: CaseNotificationType.APPEAL_TO_COURT_OF_APPEALS, + }, }, ]) } @@ -695,7 +697,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.APPEAL_RECEIVED_BY_COURT }, + body: { type: CaseNotificationType.APPEAL_RECEIVED_BY_COURT }, }, ]) } @@ -722,7 +724,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.APPEAL_COMPLETED }, + body: { type: CaseNotificationType.APPEAL_COMPLETED }, }, { type: MessageType.DELIVERY_TO_COURT_OF_APPEALS_CONCLUSION, @@ -758,7 +760,7 @@ describe('CaseController - Transition', () => { canConfirmIndictment: isIndictmentCase(theCase.type), }, caseId, - body: { type: NotificationType.APPEAL_WITHDRAWN }, + body: { type: CaseNotificationType.APPEAL_WITHDRAWN }, }, ]) } diff --git a/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts index 4939ca40beb3..088190ba98dd 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts @@ -6,6 +6,7 @@ import { CaseDecision, CaseFileCategory, CaseFileState, + CaseNotificationType, CaseOrigin, CaseState, CaseType, @@ -13,7 +14,6 @@ import { indictmentCases, InstitutionType, investigationCases, - NotificationType, restrictionCases, StringType, User, @@ -541,7 +541,7 @@ describe('CaseController - Update', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.MODIFIED }, + body: { type: CaseNotificationType.MODIFIED }, }, { type: MessageType.DELIVERY_TO_POLICE_CASE, user, caseId }, ]) @@ -598,7 +598,7 @@ describe('CaseController - Update', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.APPEAL_STATEMENT }, + body: { type: CaseNotificationType.APPEAL_STATEMENT }, }, ]) }) @@ -904,7 +904,7 @@ describe('CaseController - Update', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.COURT_DATE }, + body: { type: CaseNotificationType.COURT_DATE }, }, ]) expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledWith([ @@ -950,7 +950,7 @@ describe('CaseController - Update', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.COURT_DATE }, + body: { type: CaseNotificationType.COURT_DATE }, }, ]) }) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverConclusionToCourtOfAppeals.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverConclusionToCourtOfAppeals.spec.ts index 757a81c2982b..7fe24b98f52a 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverConclusionToCourtOfAppeals.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverConclusionToCourtOfAppeals.spec.ts @@ -1,8 +1,8 @@ import { uuid } from 'uuidv4' import { + CaseNotificationType, CaseType, - NotificationType, User, } from '@island.is/judicial-system/types' @@ -33,7 +33,10 @@ describe('InternalCaseController - Deliver conclusion to court of appeals', () = appealCaseNumber, appealRulingDecision, notifications: [ - { type: NotificationType.APPEAL_COMPLETED, created: appealRulingDate }, + { + type: CaseNotificationType.APPEAL_COMPLETED, + created: appealRulingDate, + }, ], } as Case diff --git a/apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/transition.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/transition.spec.ts index f5315d2530ec..ecfcf7793341 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/transition.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/transition.spec.ts @@ -8,10 +8,10 @@ import { CaseAppealState, CaseFileCategory, CaseFileState, + CaseNotificationType, CaseState, CaseTransition, CaseType, - NotificationType, } from '@island.is/judicial-system/types' import { createTestingCaseModule } from '../createTestingCaseModule' @@ -169,7 +169,7 @@ describe('LimitedAccessCaseController - Transition', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.APPEAL_TO_COURT_OF_APPEALS }, + body: { type: CaseNotificationType.APPEAL_TO_COURT_OF_APPEALS }, }, ]) }) @@ -218,7 +218,7 @@ describe('LimitedAccessCaseController - Transition', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.APPEAL_WITHDRAWN }, + body: { type: CaseNotificationType.APPEAL_WITHDRAWN }, }, ]) }) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/update.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/update.spec.ts index f2790b11dfec..86f711a2ded5 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/update.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/update.spec.ts @@ -4,7 +4,7 @@ import { MessageService, MessageType } from '@island.is/judicial-system/message' import { CaseFileCategory, CaseFileState, - NotificationType, + CaseNotificationType, User, } from '@island.is/judicial-system/types' @@ -111,7 +111,7 @@ describe('LimitedAccessCaseController - Update', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.APPEAL_STATEMENT }, + body: { type: CaseNotificationType.APPEAL_STATEMENT }, }, ]) }) diff --git a/apps/judicial-system/backend/src/app/modules/defendant/defendant.service.ts b/apps/judicial-system/backend/src/app/modules/defendant/defendant.service.ts index 7c38ff9f11b4..04e4a7cc8012 100644 --- a/apps/judicial-system/backend/src/app/modules/defendant/defendant.service.ts +++ b/apps/judicial-system/backend/src/app/modules/defendant/defendant.service.ts @@ -19,10 +19,9 @@ import { } from '@island.is/judicial-system/message' import type { User } from '@island.is/judicial-system/types' import { + CaseNotificationType, CaseState, CaseType, - isDistrictCourtUser, - NotificationType, } from '@island.is/judicial-system/types' import { Case } from '../case/models/case.model' @@ -50,7 +49,7 @@ export class DefendantService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: NotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT }, + body: { type: CaseNotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT }, } } diff --git a/apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/delete.spec.ts b/apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/delete.spec.ts index a9a22990ecef..7d86126c8a3c 100644 --- a/apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/delete.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/delete.spec.ts @@ -1,7 +1,7 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' -import { NotificationType, User } from '@island.is/judicial-system/types' +import { CaseNotificationType, User } from '@island.is/judicial-system/types' import { createTestingDefendantModule } from '../createTestingDefendantModule' @@ -86,7 +86,7 @@ describe('DefendantController - Delete', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT }, + body: { type: CaseNotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT }, }, ]) }) diff --git a/apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/update.spec.ts b/apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/update.spec.ts index 8b4579a3ca0a..c700fe2b3273 100644 --- a/apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/update.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/update.spec.ts @@ -1,7 +1,7 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' -import { NotificationType, User } from '@island.is/judicial-system/types' +import { CaseNotificationType, User } from '@island.is/judicial-system/types' import { createTestingDefendantModule } from '../createTestingDefendantModule' @@ -144,7 +144,7 @@ describe('DefendantController - Update', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT }, + body: { type: CaseNotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT }, }, { type: MessageType.DELIVERY_TO_COURT_DEFENDANT, diff --git a/apps/judicial-system/backend/src/app/modules/defendant/test/internalDefendantController/deliverDefendantToCourt.spec.ts b/apps/judicial-system/backend/src/app/modules/defendant/test/internalDefendantController/deliverDefendantToCourt.spec.ts index 2ff23b11b972..d3c54af319cc 100644 --- a/apps/judicial-system/backend/src/app/modules/defendant/test/internalDefendantController/deliverDefendantToCourt.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/defendant/test/internalDefendantController/deliverDefendantToCourt.spec.ts @@ -1,7 +1,7 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' -import { NotificationType, User } from '@island.is/judicial-system/types' +import { CaseNotificationType, User } from '@island.is/judicial-system/types' import { createTestingDefendantModule } from '../createTestingDefendantModule' @@ -108,7 +108,7 @@ describe('InternalDefendantController - Deliver defendant to court', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT }, + body: { type: CaseNotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT }, }, ]) }) diff --git a/apps/judicial-system/backend/src/app/modules/notification/baseNotification.service.ts b/apps/judicial-system/backend/src/app/modules/notification/baseNotification.service.ts index 211d44dcd63d..b06c0242d66f 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/baseNotification.service.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/baseNotification.service.ts @@ -129,7 +129,7 @@ export abstract class BaseNotificationService { protected async recordNotification( caseId: string, - type: NotificationType, + type: string, recipients: Recipient[], ): Promise { await this.notificationModel.create({ @@ -146,15 +146,12 @@ export abstract class BaseNotificationService { } } - protected hasSentNotification( - type: NotificationType, - notifications?: Notification[], - ) { + protected hasSentNotification(type: string, notifications?: Notification[]) { return notifications?.some((notification) => notification.type === type) } protected hasReceivedNotification( - type?: NotificationType | NotificationType[], + type?: string | string[], address?: string, notifications?: Notification[], ) { diff --git a/apps/judicial-system/backend/src/app/modules/notification/internalNotification.service.ts b/apps/judicial-system/backend/src/app/modules/notification/caseNotification.service.ts similarity index 94% rename from apps/judicial-system/backend/src/app/modules/notification/internalNotification.service.ts rename to apps/judicial-system/backend/src/app/modules/notification/caseNotification.service.ts index 40313e0c3df0..a957ef30ee93 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/internalNotification.service.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/caseNotification.service.ts @@ -34,6 +34,7 @@ import { CaseAppealRulingDecision, CaseCustodyRestrictions, CaseDecision, + CaseNotificationType, CaseState, CaseType, getStatementDeadline, @@ -43,7 +44,6 @@ import { isProsecutionUser, isRequestCase, isRestrictionCase, - NotificationType, RequestSharedWithDefender, SessionArrangements, type User, @@ -97,7 +97,7 @@ interface RecipientInfo { } @Injectable() -export class InternalNotificationService extends BaseNotificationService { +export class CaseNotificationService extends BaseNotificationService { constructor( @InjectModel(Notification) notificationModel: typeof Notification, @@ -252,7 +252,7 @@ export class InternalNotificationService extends BaseNotificationService { ): Promise { const recipient = await this.sendHeadsUpSmsNotificationToCourt(theCase) - return this.recordNotification(theCase.id, NotificationType.HEADS_UP, [ + return this.recordNotification(theCase.id, CaseNotificationType.HEADS_UP, [ recipient, ]) } @@ -374,7 +374,7 @@ export class InternalNotificationService extends BaseNotificationService { ) return this.recordNotification( theCase.id, - NotificationType.READY_FOR_COURT, + CaseNotificationType.READY_FOR_COURT, [recipient], ) } @@ -385,7 +385,7 @@ export class InternalNotificationService extends BaseNotificationService { ] const courtHasBeenNotified = this.hasReceivedNotification( - NotificationType.READY_FOR_COURT, + CaseNotificationType.READY_FOR_COURT, this.getCourtMobileNumbers(theCase.courtId), theCase.notifications, ) @@ -404,7 +404,7 @@ export class InternalNotificationService extends BaseNotificationService { theCase.requestSharedWithDefender === RequestSharedWithDefender.COURT_DATE ) { const hasDefenderBeenNotified = this.hasReceivedNotification( - [NotificationType.READY_FOR_COURT, NotificationType.COURT_DATE], + [CaseNotificationType.READY_FOR_COURT, CaseNotificationType.COURT_DATE], theCase.defenderEmail, theCase.notifications, ) @@ -428,7 +428,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.READY_FOR_COURT, + CaseNotificationType.READY_FOR_COURT, recipients, ) } @@ -457,7 +457,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.RECEIVED_BY_COURT, + CaseNotificationType.RECEIVED_BY_COURT, [recipient], ) } @@ -778,7 +778,7 @@ export class InternalNotificationService extends BaseNotificationService { ) const hasDefenderBeenNotified = this.hasReceivedNotification( - [NotificationType.READY_FOR_COURT], + [CaseNotificationType.READY_FOR_COURT], theCase.defenderEmail, theCase.notifications, ) @@ -806,7 +806,7 @@ export class InternalNotificationService extends BaseNotificationService { const result = await this.recordNotification( theCase.id, - NotificationType.COURT_DATE, + CaseNotificationType.COURT_DATE, recipients, ) @@ -1049,7 +1049,7 @@ export class InternalNotificationService extends BaseNotificationService { theCase.decision === CaseDecision.ACCEPTING_ALTERNATIVE_TRAVEL_BAN) ) { const prisonHasBeenNotified = this.hasReceivedNotification( - NotificationType.COURT_DATE, + CaseNotificationType.COURT_DATE, this.config.email.prisonEmail, theCase.notifications, ) @@ -1063,7 +1063,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.RULING, + CaseNotificationType.RULING, recipients, ) } @@ -1214,7 +1214,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.MODIFIED, + CaseNotificationType.MODIFIED, recipients, ) } @@ -1388,7 +1388,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.REVOKED, + CaseNotificationType.REVOKED, recipients, ) } @@ -1484,7 +1484,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.REVOKED, + CaseNotificationType.REVOKED, recipients, ) } @@ -1508,7 +1508,7 @@ export class InternalNotificationService extends BaseNotificationService { } if (isIndictmentCase(theCase.type)) { const hasSentNotificationBefore = this.hasReceivedNotification( - NotificationType.ADVOCATE_ASSIGNED, + CaseNotificationType.ADVOCATE_ASSIGNED, advocateEmail, theCase.notifications, ) @@ -1530,9 +1530,9 @@ export class InternalNotificationService extends BaseNotificationService { } else { const hasDefenderBeenNotified = this.hasReceivedNotification( [ - NotificationType.READY_FOR_COURT, - NotificationType.COURT_DATE, - NotificationType.ADVOCATE_ASSIGNED, + CaseNotificationType.READY_FOR_COURT, + CaseNotificationType.COURT_DATE, + CaseNotificationType.ADVOCATE_ASSIGNED, ], theCase.defenderEmail, theCase.notifications, @@ -1655,7 +1655,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.ADVOCATE_ASSIGNED, + CaseNotificationType.ADVOCATE_ASSIGNED, recipients, ) } @@ -1668,7 +1668,7 @@ export class InternalNotificationService extends BaseNotificationService { if ( !theCase.registrar || this.hasReceivedNotification( - NotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT, + CaseNotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT, theCase.registrar?.email, theCase.notifications, ) @@ -1699,7 +1699,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT, + CaseNotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT, [recipient], ) } @@ -1725,7 +1725,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.INDICTMENT_DENIED, + CaseNotificationType.INDICTMENT_DENIED, [recipient], ) } @@ -1757,7 +1757,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.INDICTMENT_RETURNED, + CaseNotificationType.INDICTMENT_RETURNED, [recipient], ) } @@ -1864,7 +1864,7 @@ export class InternalNotificationService extends BaseNotificationService { if (recipients.length > 0) { return this.recordNotification( theCase.id, - NotificationType.CASE_FILES_UPDATED, + CaseNotificationType.CASE_FILES_UPDATED, recipients, ) } @@ -1909,7 +1909,7 @@ export class InternalNotificationService extends BaseNotificationService { if (recipients.length > 0) { return this.recordNotification( theCase.id, - NotificationType.APPEAL_JUDGES_ASSIGNED, + CaseNotificationType.APPEAL_JUDGES_ASSIGNED, recipients, ) } @@ -2017,7 +2017,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.APPEAL_TO_COURT_OF_APPEALS, + CaseNotificationType.APPEAL_TO_COURT_OF_APPEALS, recipients, ) } @@ -2119,7 +2119,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.APPEAL_RECEIVED_BY_COURT, + CaseNotificationType.APPEAL_RECEIVED_BY_COURT, recipients, ) } @@ -2256,7 +2256,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.APPEAL_STATEMENT, + CaseNotificationType.APPEAL_STATEMENT, recipients, ) } @@ -2332,7 +2332,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.APPEAL_CASE_FILES_UPDATED, + CaseNotificationType.APPEAL_CASE_FILES_UPDATED, recipients, ) } @@ -2343,7 +2343,7 @@ export class InternalNotificationService extends BaseNotificationService { theCase: Case, ): Promise { const isReopened = this.hasSentNotification( - NotificationType.APPEAL_COMPLETED, + CaseNotificationType.APPEAL_COMPLETED, theCase.notifications, ) const promises = [] @@ -2507,7 +2507,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.APPEAL_COMPLETED, + CaseNotificationType.APPEAL_COMPLETED, recipients, ) } @@ -2550,7 +2550,7 @@ export class InternalNotificationService extends BaseNotificationService { return this.recordNotification( theCase.id, - NotificationType.APPEAL_WITHDRAWN, + CaseNotificationType.APPEAL_WITHDRAWN, recipients, ) } @@ -2561,7 +2561,7 @@ export class InternalNotificationService extends BaseNotificationService { wasWithdrawnByProsecution: boolean, ): RecipientInfo[] { const hasBeenAssigned = this.hasSentNotification( - NotificationType.APPEAL_JUDGES_ASSIGNED, + CaseNotificationType.APPEAL_JUDGES_ASSIGNED, theCase.notifications, ) @@ -2634,63 +2634,71 @@ export class InternalNotificationService extends BaseNotificationService { //#endregion //#region API + private sendNotification( + type: CaseNotificationType, + theCase: Case, + user: User, + ): Promise { + switch (type) { + case CaseNotificationType.HEADS_UP: + return this.sendHeadsUpNotifications(theCase) + case CaseNotificationType.READY_FOR_COURT: + return this.sendReadyForCourtNotifications(theCase) + case CaseNotificationType.RECEIVED_BY_COURT: + return this.sendReceivedByCourtNotifications(theCase) + case CaseNotificationType.COURT_DATE: + return this.sendCourtDateNotifications(theCase, user) + case CaseNotificationType.RULING: + return this.sendRulingNotifications(theCase) + case CaseNotificationType.MODIFIED: + return this.sendModifiedNotifications(theCase, user) + case CaseNotificationType.REVOKED: + return this.sendRevokedNotifications(theCase) + case CaseNotificationType.ADVOCATE_ASSIGNED: + return this.sendAdvocateAssignedNotifications(theCase) + case CaseNotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT: + return this.sendDefendantsNotUpdatedAtCourtNotifications(theCase) + case CaseNotificationType.APPEAL_TO_COURT_OF_APPEALS: + return this.sendAppealToCourtOfAppealsNotifications(theCase, user) + case CaseNotificationType.APPEAL_RECEIVED_BY_COURT: + return this.sendAppealReceivedByCourtNotifications(theCase) + case CaseNotificationType.APPEAL_STATEMENT: + return this.sendAppealStatementNotifications(theCase, user) + case CaseNotificationType.APPEAL_COMPLETED: + return this.sendAppealCompletedNotifications(theCase) + case CaseNotificationType.APPEAL_JUDGES_ASSIGNED: + return this.sendCourtOfAppealJudgeAssignedNotification(theCase) + case CaseNotificationType.APPEAL_CASE_FILES_UPDATED: + return this.sendAppealCaseFilesUpdatedNotifications(theCase, user) + case CaseNotificationType.APPEAL_WITHDRAWN: + return this.sendAppealWithdrawnNotifications(theCase, user) + case CaseNotificationType.INDICTMENT_DENIED: + return this.sendIndictmentDeniedNotifications(theCase) + case CaseNotificationType.INDICTMENT_RETURNED: + return this.sendIndictmentReturnedNotifications(theCase) + case CaseNotificationType.CASE_FILES_UPDATED: + return this.sendCaseFilesUpdatedNotifications(theCase, user) + default: + throw new InternalServerErrorException( + `Invalid notification type ${type}`, + ) + } + } + async sendCaseNotification( - type: NotificationType, + type: CaseNotificationType, theCase: Case, user: User, ): Promise { await this.refreshFormatMessage() try { - switch (type) { - case NotificationType.HEADS_UP: - return this.sendHeadsUpNotifications(theCase) - case NotificationType.READY_FOR_COURT: - return this.sendReadyForCourtNotifications(theCase) - case NotificationType.RECEIVED_BY_COURT: - return this.sendReceivedByCourtNotifications(theCase) - case NotificationType.COURT_DATE: - return this.sendCourtDateNotifications(theCase, user) - case NotificationType.RULING: - return this.sendRulingNotifications(theCase) - case NotificationType.MODIFIED: - return this.sendModifiedNotifications(theCase, user) - case NotificationType.REVOKED: - return this.sendRevokedNotifications(theCase) - case NotificationType.ADVOCATE_ASSIGNED: - return this.sendAdvocateAssignedNotifications(theCase) - case NotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT: - return this.sendDefendantsNotUpdatedAtCourtNotifications(theCase) - case NotificationType.APPEAL_TO_COURT_OF_APPEALS: - return this.sendAppealToCourtOfAppealsNotifications(theCase, user) - case NotificationType.APPEAL_RECEIVED_BY_COURT: - return this.sendAppealReceivedByCourtNotifications(theCase) - case NotificationType.APPEAL_STATEMENT: - return this.sendAppealStatementNotifications(theCase, user) - case NotificationType.APPEAL_COMPLETED: - return this.sendAppealCompletedNotifications(theCase) - case NotificationType.APPEAL_JUDGES_ASSIGNED: - return this.sendCourtOfAppealJudgeAssignedNotification(theCase) - case NotificationType.APPEAL_CASE_FILES_UPDATED: - return this.sendAppealCaseFilesUpdatedNotifications(theCase, user) - case NotificationType.APPEAL_WITHDRAWN: - return this.sendAppealWithdrawnNotifications(theCase, user) - case NotificationType.INDICTMENT_DENIED: - return this.sendIndictmentDeniedNotifications(theCase) - case NotificationType.INDICTMENT_RETURNED: - return this.sendIndictmentReturnedNotifications(theCase) - case NotificationType.CASE_FILES_UPDATED: - return this.sendCaseFilesUpdatedNotifications(theCase, user) - default: - throw new InternalServerErrorException( - `Invalid notification type ${type}`, - ) - } + return await this.sendNotification(type, theCase, user) } catch (error) { this.logger.error('Failed to send notification', error) return { delivered: false } } - //#endregion } + //#endregion } diff --git a/apps/judicial-system/backend/src/app/modules/notification/dto/caseNotification.dto.ts b/apps/judicial-system/backend/src/app/modules/notification/dto/caseNotification.dto.ts index c0ca592a5408..04e71583b08a 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/dto/caseNotification.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/dto/caseNotification.dto.ts @@ -3,7 +3,7 @@ import { IsEnum, IsNotEmpty, IsObject } from 'class-validator' import { ApiProperty } from '@nestjs/swagger' import type { User } from '@island.is/judicial-system/types' -import { NotificationType } from '@island.is/judicial-system/types' +import { CaseNotificationType } from '@island.is/judicial-system/types' export class CaseNotificationDto { @IsNotEmpty() @@ -12,7 +12,7 @@ export class CaseNotificationDto { readonly user!: User @IsNotEmpty() - @IsEnum(NotificationType) - @ApiProperty({ enum: NotificationType }) - readonly type!: NotificationType + @IsEnum(CaseNotificationType) + @ApiProperty({ enum: CaseNotificationType }) + readonly type!: CaseNotificationType } diff --git a/apps/judicial-system/backend/src/app/modules/notification/dto/institutionNotification.dto.ts b/apps/judicial-system/backend/src/app/modules/notification/dto/institutionNotification.dto.ts index ec4de22f7074..18a8dc7d72aa 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/dto/institutionNotification.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/dto/institutionNotification.dto.ts @@ -2,13 +2,13 @@ import { IsEnum, IsNotEmpty, IsUUID } from 'class-validator' import { ApiProperty } from '@nestjs/swagger' -import { NotificationType } from '@island.is/judicial-system/types' +import { InstitutionNotificationType } from '@island.is/judicial-system/types' export class InstitutionNotificationDto { @IsNotEmpty() - @IsEnum(NotificationType) - @ApiProperty({ enum: NotificationType }) - readonly type!: NotificationType + @IsEnum(InstitutionNotificationType) + @ApiProperty({ enum: InstitutionNotificationType }) + readonly type!: InstitutionNotificationType @IsNotEmpty() @IsUUID() diff --git a/apps/judicial-system/backend/src/app/modules/notification/dto/notification.dto.ts b/apps/judicial-system/backend/src/app/modules/notification/dto/notification.dto.ts index f2e5d5981df6..72f30554a31b 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/dto/notification.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/dto/notification.dto.ts @@ -2,13 +2,13 @@ import { IsBoolean, IsEnum, IsNotEmpty, IsOptional } from 'class-validator' import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger' -import { NotificationType } from '@island.is/judicial-system/types' +import { CaseNotificationType } from '@island.is/judicial-system/types' export class NotificationDto { @IsNotEmpty() - @IsEnum(NotificationType) - @ApiProperty({ enum: NotificationType }) - readonly type!: NotificationType + @IsEnum(CaseNotificationType) + @ApiProperty({ enum: CaseNotificationType }) + readonly type!: CaseNotificationType @IsOptional() @IsBoolean() diff --git a/apps/judicial-system/backend/src/app/modules/notification/dto/notificationDispatch.dto.ts b/apps/judicial-system/backend/src/app/modules/notification/dto/notificationDispatch.dto.ts new file mode 100644 index 000000000000..017f7a7fde0d --- /dev/null +++ b/apps/judicial-system/backend/src/app/modules/notification/dto/notificationDispatch.dto.ts @@ -0,0 +1,12 @@ +import { IsEnum, IsNotEmpty } from 'class-validator' + +import { ApiProperty } from '@nestjs/swagger' + +import { NotificationDispatchType } from '@island.is/judicial-system/types' + +export class NotificationDispatchDto { + @IsNotEmpty() + @IsEnum(NotificationDispatchType) + @ApiProperty({ enum: NotificationDispatchType }) + readonly type!: NotificationDispatchType +} diff --git a/apps/judicial-system/backend/src/app/modules/notification/dto/subpoenaNotification.dto.ts b/apps/judicial-system/backend/src/app/modules/notification/dto/subpoenaNotification.dto.ts index e1b0bf519135..76d8ce557a28 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/dto/subpoenaNotification.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/dto/subpoenaNotification.dto.ts @@ -2,17 +2,11 @@ import { IsEnum, IsNotEmpty } from 'class-validator' import { ApiProperty } from '@nestjs/swagger' -import { NotificationType } from '@island.is/judicial-system/types' - -import { Subpoena } from '../../subpoena' +import { SubpoenaNotificationType } from '@island.is/judicial-system/types' export class SubpoenaNotificationDto { @IsNotEmpty() - @IsEnum(NotificationType) - @ApiProperty({ enum: NotificationType }) - readonly type!: NotificationType - - @IsNotEmpty() - @ApiProperty({ type: Subpoena }) - readonly subpoena!: Subpoena + @IsEnum(SubpoenaNotificationType) + @ApiProperty({ enum: SubpoenaNotificationType }) + readonly type!: SubpoenaNotificationType } diff --git a/apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts b/apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts index dd5a3153797e..37de4e092f04 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts @@ -1,5 +1,8 @@ import { RolesRule, RulesType } from '@island.is/judicial-system/auth' -import { NotificationType, UserRole } from '@island.is/judicial-system/types' +import { + CaseNotificationType, + UserRole, +} from '@island.is/judicial-system/types' // Allows prosecutors to send notifications export const prosecutorNotificationRule: RolesRule = { @@ -7,10 +10,10 @@ export const prosecutorNotificationRule: RolesRule = { type: RulesType.FIELD_VALUES, dtoField: 'type', dtoFieldValues: [ - NotificationType.HEADS_UP, - NotificationType.READY_FOR_COURT, - NotificationType.APPEAL_CASE_FILES_UPDATED, - NotificationType.CASE_FILES_UPDATED, + CaseNotificationType.HEADS_UP, + CaseNotificationType.READY_FOR_COURT, + CaseNotificationType.APPEAL_CASE_FILES_UPDATED, + CaseNotificationType.CASE_FILES_UPDATED, ], } as RolesRule @@ -20,8 +23,8 @@ export const defenderNotificationRule: RolesRule = { type: RulesType.FIELD_VALUES, dtoField: 'type', dtoFieldValues: [ - NotificationType.APPEAL_CASE_FILES_UPDATED, - NotificationType.CASE_FILES_UPDATED, + CaseNotificationType.APPEAL_CASE_FILES_UPDATED, + CaseNotificationType.CASE_FILES_UPDATED, ], } as RolesRule @@ -31,8 +34,8 @@ export const districtCourtJudgeNotificationRule: RolesRule = { type: RulesType.FIELD_VALUES, dtoField: 'type', dtoFieldValues: [ - NotificationType.COURT_DATE, - NotificationType.ADVOCATE_ASSIGNED, + CaseNotificationType.COURT_DATE, + CaseNotificationType.ADVOCATE_ASSIGNED, ], } @@ -42,8 +45,8 @@ export const districtCourtRegistrarNotificationRule: RolesRule = { type: RulesType.FIELD_VALUES, dtoField: 'type', dtoFieldValues: [ - NotificationType.COURT_DATE, - NotificationType.ADVOCATE_ASSIGNED, + CaseNotificationType.COURT_DATE, + CaseNotificationType.ADVOCATE_ASSIGNED, ], } @@ -53,8 +56,8 @@ export const districtCourtAssistantNotificationRule: RolesRule = { type: RulesType.FIELD_VALUES, dtoField: 'type', dtoFieldValues: [ - NotificationType.COURT_DATE, - NotificationType.ADVOCATE_ASSIGNED, + CaseNotificationType.COURT_DATE, + CaseNotificationType.ADVOCATE_ASSIGNED, ], } @@ -63,7 +66,7 @@ export const courtOfAppealsJudgeNotificationRule: RolesRule = { role: UserRole.COURT_OF_APPEALS_JUDGE, type: RulesType.FIELD_VALUES, dtoField: 'type', - dtoFieldValues: [NotificationType.APPEAL_JUDGES_ASSIGNED], + dtoFieldValues: [CaseNotificationType.APPEAL_JUDGES_ASSIGNED], } // Allows court of appeals registrars to send notifications @@ -71,7 +74,7 @@ export const courtOfAppealsRegistrarNotificationRule: RolesRule = { role: UserRole.COURT_OF_APPEALS_REGISTRAR, type: RulesType.FIELD_VALUES, dtoField: 'type', - dtoFieldValues: [NotificationType.APPEAL_JUDGES_ASSIGNED], + dtoFieldValues: [CaseNotificationType.APPEAL_JUDGES_ASSIGNED], } // Allows court of appeals assistants to send notifications @@ -79,5 +82,5 @@ export const courtOfAppealsAssistantNotificationRule: RolesRule = { role: UserRole.COURT_OF_APPEALS_ASSISTANT, type: RulesType.FIELD_VALUES, dtoField: 'type', - dtoFieldValues: [NotificationType.APPEAL_JUDGES_ASSIGNED], + dtoFieldValues: [CaseNotificationType.APPEAL_JUDGES_ASSIGNED], } diff --git a/apps/judicial-system/backend/src/app/modules/notification/institutionNotification.service.ts b/apps/judicial-system/backend/src/app/modules/notification/institutionNotification.service.ts index cad5fba282fa..82727cab9a70 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/institutionNotification.service.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/institutionNotification.service.ts @@ -10,7 +10,7 @@ import { EmailService } from '@island.is/email-service' import { type Logger, LOGGER_PROVIDER } from '@island.is/logging' import { type ConfigType } from '@island.is/nest/config' -import { NotificationType } from '@island.is/judicial-system/types' +import { InstitutionNotificationType } from '@island.is/judicial-system/types' import { InternalCaseService } from '../case' import { EventService } from '../event' @@ -46,12 +46,8 @@ export class InstitutionNotificationService extends BaseNotificationService { } private async sendIndictmentsWaitingForConfirmationNotification( - prosecutorsOfficeId?: string, + prosecutorsOfficeId: string, ): Promise { - if (!prosecutorsOfficeId) { - return - } - const count = await this.internalCaseService.countIndictmentsWaitingForConfirmation( prosecutorsOfficeId, @@ -90,12 +86,12 @@ export class InstitutionNotificationService extends BaseNotificationService { } async sendNotification( - type: NotificationType, - prosecutorsOfficeId?: string, + type: InstitutionNotificationType, + prosecutorsOfficeId: string, ): Promise { try { switch (type) { - case NotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION: + case InstitutionNotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION: await this.sendIndictmentsWaitingForConfirmationNotification( prosecutorsOfficeId, ) diff --git a/apps/judicial-system/backend/src/app/modules/notification/internalNotification.controller.ts b/apps/judicial-system/backend/src/app/modules/notification/internalNotification.controller.ts index 2b96d6aaac7a..9e292ba48cdc 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/internalNotification.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/internalNotification.controller.ts @@ -18,12 +18,15 @@ import { } from '@island.is/judicial-system/message' import { Case, CaseHasExistedGuard, CurrentCase } from '../case' +import { DefendantExistsGuard } from '../defendant' +import { SubpoenaExistsGuard } from '../subpoena' import { CaseNotificationDto } from './dto/caseNotification.dto' import { InstitutionNotificationDto } from './dto/institutionNotification.dto' +import { NotificationDispatchDto } from './dto/notificationDispatch.dto' import { SubpoenaNotificationDto } from './dto/subpoenaNotification.dto' import { DeliverResponse } from './models/deliver.response' +import { CaseNotificationService } from './caseNotification.service' import { InstitutionNotificationService } from './institutionNotification.service' -import { InternalNotificationService } from './internalNotification.service' import { NotificationDispatchService } from './notificationDispatch.service' import { SubpoenaNotificationService } from './subpoenaNotification.service' @@ -32,7 +35,7 @@ import { SubpoenaNotificationService } from './subpoenaNotification.service' @ApiTags('internal notifications') export class InternalNotificationController { constructor( - private readonly internalNotificationService: InternalNotificationService, + private readonly caseNotificationService: CaseNotificationService, private readonly notificationDispatchService: NotificationDispatchService, private readonly institutionNotificationService: InstitutionNotificationService, private readonly subpoenaNotificationService: SubpoenaNotificationService, @@ -43,7 +46,7 @@ export class InternalNotificationController { @UseGuards(CaseHasExistedGuard) @ApiCreatedResponse({ type: DeliverResponse, - description: 'Sends a new notification for an existing case', + description: 'Sends a case notification for an existing case', }) sendCaseNotification( @Param('caseId') caseId: string, @@ -51,60 +54,71 @@ export class InternalNotificationController { @Body() notificationDto: CaseNotificationDto, ): Promise { this.logger.debug( - `Sending ${notificationDto.type} notification for case ${caseId}`, + `Sending ${notificationDto.type} case notification for case ${caseId}`, ) - return this.internalNotificationService.sendCaseNotification( + return this.caseNotificationService.sendCaseNotification( notificationDto.type, theCase, notificationDto.user, ) } - @Post(messageEndpoint[MessageType.NOTIFICATION]) + @Post( + `case/:caseId/${ + messageEndpoint[MessageType.SUBPOENA_NOTIFICATION] + }/:defendantId/:subpoenaId`, + ) + @UseGuards(CaseHasExistedGuard, DefendantExistsGuard, SubpoenaExistsGuard) @ApiCreatedResponse({ type: DeliverResponse, - description: 'Sends a new notification', + description: 'Sends a subpoena notification for an existing subpoena', }) - sendNotification( - @Body() notificationDto: InstitutionNotificationDto, + sendSubpoenaNotification( + @Param('caseId') caseId: string, + @Param('defendantId') defendantId: string, + @Param('subpoenaId') subpoenaId: string, + @CurrentCase() theCase: Case, + @Body() notificationDto: SubpoenaNotificationDto, ): Promise { - this.logger.debug(`Sending ${notificationDto.type} notification`) + this.logger.debug( + `Sending ${notificationDto.type} subpoena notification for subpoena ${subpoenaId} of defendant ${defendantId} and case ${caseId}`, + ) - return this.institutionNotificationService.sendNotification( + return this.subpoenaNotificationService.sendSubpoenaNotification( notificationDto.type, - notificationDto.prosecutorsOfficeId, + theCase, ) } - @Post(messageEndpoint[MessageType.SUBPOENA_NOTIFICATION]) + @Post(messageEndpoint[MessageType.NOTIFICATION_DISPATCH]) @ApiCreatedResponse({ type: DeliverResponse, - description: 'Sends a new notification', + description: 'Dispatches notifications', }) - sendSubpoenaNotification( - @Body() notificationDto: SubpoenaNotificationDto, + dispatchNotification( + @Body() notificationDto: NotificationDispatchDto, ): Promise { - this.logger.debug(`Sending ${notificationDto.type} notification`) + this.logger.debug(`Dispatching ${notificationDto.type} notification`) - return this.subpoenaNotificationService.sendNotification( + return this.notificationDispatchService.dispatchNotification( notificationDto.type, - notificationDto.subpoena, ) } - @Post(messageEndpoint[MessageType.NOTIFICATION_DISPATCH]) + @Post(messageEndpoint[MessageType.INSTITUTION_NOTIFICATION]) @ApiCreatedResponse({ type: DeliverResponse, - description: 'Dispatches notifications', + description: 'Sends an institution notification', }) - dispatchNotification( + sendNotification( @Body() notificationDto: InstitutionNotificationDto, ): Promise { - this.logger.debug(`Dispatching ${notificationDto.type} notification`) + this.logger.debug(`Sending ${notificationDto.type} notification`) - return this.notificationDispatchService.dispatchNotification( + return this.institutionNotificationService.sendNotification( notificationDto.type, + notificationDto.prosecutorsOfficeId, ) } } diff --git a/apps/judicial-system/backend/src/app/modules/notification/notification.module.ts b/apps/judicial-system/backend/src/app/modules/notification/notification.module.ts index f2c3054e7845..059460e77873 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/notification.module.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/notification.module.ts @@ -17,9 +17,9 @@ import { UserModule, } from '../index' import { Notification } from './models/notification.model' +import { CaseNotificationService } from './caseNotification.service' import { InstitutionNotificationService } from './institutionNotification.service' import { InternalNotificationController } from './internalNotification.controller' -import { InternalNotificationService } from './internalNotification.service' import { NotificationController } from './notification.controller' import { NotificationService } from './notification.service' import { NotificationDispatchService } from './notificationDispatch.service' @@ -43,7 +43,7 @@ import { SubpoenaNotificationService } from './subpoenaNotification.service' controllers: [NotificationController, InternalNotificationController], providers: [ NotificationService, - InternalNotificationService, + CaseNotificationService, NotificationDispatchService, InstitutionNotificationService, SubpoenaNotificationService, diff --git a/apps/judicial-system/backend/src/app/modules/notification/notification.service.ts b/apps/judicial-system/backend/src/app/modules/notification/notification.service.ts index be058b8463e2..25bb2c672d4b 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/notification.service.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/notification.service.ts @@ -8,7 +8,10 @@ import { MessageType, } from '@island.is/judicial-system/message' import { type User } from '@island.is/judicial-system/types' -import { CaseState, NotificationType } from '@island.is/judicial-system/types' +import { + CaseNotificationType, + CaseState, +} from '@island.is/judicial-system/types' import { type Case } from '../case' import { EventService } from '../event' @@ -22,7 +25,7 @@ export class NotificationService { ) {} private getNotificationMessage( - type: NotificationType, + type: CaseNotificationType, user: User, theCase: Case, ): Message { @@ -35,7 +38,7 @@ export class NotificationService { } async addNotificationMessagesToQueue( - type: NotificationType, + type: CaseNotificationType, eventOnly = false, theCase: Case, user: User, @@ -43,7 +46,7 @@ export class NotificationService { let messages: Message[] switch (type) { - case NotificationType.READY_FOR_COURT: + case CaseNotificationType.READY_FOR_COURT: messages = [this.getNotificationMessage(type, user, theCase)] if (theCase.state === CaseState.RECEIVED) { @@ -54,7 +57,7 @@ export class NotificationService { }) } break - case NotificationType.COURT_DATE: + case CaseNotificationType.COURT_DATE: if (eventOnly) { this.eventService.postEvent('SCHEDULE_COURT_DATE', theCase, true) @@ -62,7 +65,7 @@ export class NotificationService { // the judge chooses not to send a calendar invitation messages = [ this.getNotificationMessage( - NotificationType.ADVOCATE_ASSIGNED, + CaseNotificationType.ADVOCATE_ASSIGNED, user, theCase, ), @@ -71,11 +74,11 @@ export class NotificationService { messages = [this.getNotificationMessage(type, user, theCase)] } break - case NotificationType.HEADS_UP: - case NotificationType.ADVOCATE_ASSIGNED: - case NotificationType.APPEAL_JUDGES_ASSIGNED: - case NotificationType.APPEAL_CASE_FILES_UPDATED: - case NotificationType.CASE_FILES_UPDATED: + case CaseNotificationType.HEADS_UP: + case CaseNotificationType.ADVOCATE_ASSIGNED: + case CaseNotificationType.APPEAL_JUDGES_ASSIGNED: + case CaseNotificationType.APPEAL_CASE_FILES_UPDATED: + case CaseNotificationType.CASE_FILES_UPDATED: messages = [this.getNotificationMessage(type, user, theCase)] break default: diff --git a/apps/judicial-system/backend/src/app/modules/notification/notificationDispatch.service.ts b/apps/judicial-system/backend/src/app/modules/notification/notificationDispatch.service.ts index c2fb9e9555d8..13884be1e9e0 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/notificationDispatch.service.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/notificationDispatch.service.ts @@ -8,8 +8,9 @@ import { type Logger, LOGGER_PROVIDER } from '@island.is/logging' import { MessageService, MessageType } from '@island.is/judicial-system/message' import { + InstitutionNotificationType, InstitutionType, - NotificationType, + NotificationDispatchType, } from '@island.is/judicial-system/types' import { Institution, InstitutionService } from '../institution' @@ -30,9 +31,9 @@ export class NotificationDispatchService { const messages = prosecutorsOffices.map( (prosecutorsOffice: Institution) => ({ - type: MessageType.NOTIFICATION, + type: MessageType.INSTITUTION_NOTIFICATION, body: { - type: NotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION, + type: InstitutionNotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION, prosecutorsOfficeId: prosecutorsOffice.id, }, }), @@ -41,10 +42,12 @@ export class NotificationDispatchService { return this.messageService.sendMessagesToQueue(messages) } - async dispatchNotification(type: NotificationType): Promise { + async dispatchNotification( + type: NotificationDispatchType, + ): Promise { try { switch (type) { - case NotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION: + case NotificationDispatchType.INDICTMENTS_WAITING_FOR_CONFIRMATION: await this.dispatchIndictmentsWaitingForConfirmationNotification() break default: diff --git a/apps/judicial-system/backend/src/app/modules/notification/subpoenaNotification.service.ts b/apps/judicial-system/backend/src/app/modules/notification/subpoenaNotification.service.ts index a8ac52f19be1..61b9e9a86a00 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/subpoenaNotification.service.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/subpoenaNotification.service.ts @@ -1,4 +1,4 @@ -import { MessageDescriptor } from 'react-intl' +import { MessageDescriptor } from '@formatjs/intl' import { Inject, @@ -13,21 +13,16 @@ import { type Logger, LOGGER_PROVIDER } from '@island.is/logging' import { type ConfigType } from '@island.is/nest/config' import { INDICTMENTS_COURT_OVERVIEW_ROUTE } from '@island.is/judicial-system/consts' -import { NotificationType } from '@island.is/judicial-system/types' +import { SubpoenaNotificationType } from '@island.is/judicial-system/types' +import { Case } from '../case' import { EventService } from '../event' -import { Subpoena } from '../subpoena' import { DeliverResponse } from './models/deliver.response' import { Notification, Recipient } from './models/notification.model' import { BaseNotificationService } from './baseNotification.service' import { notificationModuleConfig } from './notification.config' import { strings } from './subpoenaNotification.strings' -type SubpoenaNotificationType = - | NotificationType.SERVICE_SUCCESSFUL - | NotificationType.SERVICE_FAILED - | NotificationType.DEFENDANT_SELECTED_DEFENDER - @Injectable() export class SubpoenaNotificationService extends BaseNotificationService { constructor( @@ -50,121 +45,43 @@ export class SubpoenaNotificationService extends BaseNotificationService { ) } - private getEmailContents(notificationType: SubpoenaNotificationType): { - subject: MessageDescriptor - body: MessageDescriptor - } { - switch (notificationType) { - case NotificationType.SERVICE_SUCCESSFUL: - return { - subject: strings.serviceSuccessfulSubject, - body: strings.serviceSuccessfulBody, - } - case NotificationType.SERVICE_FAILED: - return { - subject: strings.serviceFailedSubject, - body: strings.serviceFailedBody, - } - case NotificationType.DEFENDANT_SELECTED_DEFENDER: - return { - subject: strings.defendantSelectedDefenderSubject, - body: strings.defendantSelectedDefenderBody, - } - default: - throw new InternalServerErrorException('Email contents not found') - } - } - - private async sendSubpoenaNotification( + private async sendEmails( + theCase: Case, notificationType: SubpoenaNotificationType, - subpoena: Subpoena, - ): Promise { - const theCase = subpoena.case - - if (!theCase) { - throw new InternalServerErrorException('Missing case') - } - - const hasSentSuccessfulServiceNotification = Boolean( - this.hasSentNotification( - NotificationType.SERVICE_SUCCESSFUL, - theCase.notifications, - ) && notificationType === NotificationType.SERVICE_SUCCESSFUL, - ) - - const hasSentFailedServiceNotification = Boolean( - this.hasSentNotification( - NotificationType.SERVICE_FAILED, - theCase.notifications, - ) && notificationType === NotificationType.SERVICE_FAILED, - ) - - const hasSendDefendantSelectedDefenderNotification = Boolean( - this.hasSentNotification( - NotificationType.DEFENDANT_SELECTED_DEFENDER, - theCase.notifications, - ) && notificationType === NotificationType.DEFENDANT_SELECTED_DEFENDER, - ) - - if ( - hasSentSuccessfulServiceNotification || - hasSentFailedServiceNotification || - hasSendDefendantSelectedDefenderNotification - ) { - return - } - - await this.refreshFormatMessage() - - const emailContents = this.getEmailContents(notificationType) - - const formattedSubject = this.formatMessage(emailContents.subject, { + subject: MessageDescriptor, + body: MessageDescriptor, + ) { + const formattedSubject = this.formatMessage(subject, { courtCaseNumber: theCase.courtCaseNumber, }) - const formattedBody = this.formatMessage(emailContents.body, { + const formattedBody = this.formatMessage(body, { courtCaseNumber: theCase.courtCaseNumber, linkStart: ``, linkEnd: '', }) - - return this.sendEmails( - theCase.id, - notificationType, - formattedSubject, - formattedBody, - theCase.judge?.name, - theCase.judge?.email, - theCase.registrar?.name, - theCase.registrar?.email, - ) - } - - private async sendEmails( - caseId: string, - notificationType: SubpoenaNotificationType, - subject: string, - body: string, - judgeName?: string, - judgeEmail?: string, - registrarName?: string, - registrarEmail?: string, - ) { const promises: Promise[] = [] - if (judgeName && judgeEmail) { + if (theCase.judge?.email) { promises.push( - this.sendEmail(subject, body, judgeName, judgeEmail, undefined, true), + this.sendEmail( + formattedSubject, + formattedBody, + theCase.judge.name, + theCase.judge.email, + undefined, + true, + ), ) } - if (registrarName && registrarEmail) { + if (theCase.registrar?.email) { promises.push( this.sendEmail( - subject, - body, - registrarName, - registrarEmail, + formattedSubject, + formattedBody, + theCase.registrar.name, + theCase.registrar.email, undefined, true, ), @@ -173,24 +90,72 @@ export class SubpoenaNotificationService extends BaseNotificationService { const recipients = await Promise.all(promises) - return this.recordNotification(caseId, notificationType, recipients) + return this.recordNotification(theCase.id, notificationType, recipients) + } + + private sendServiceSuccessfulNotification( + theCase: Case, + ): Promise { + return this.sendEmails( + theCase, + SubpoenaNotificationType.SERVICE_SUCCESSFUL, + strings.serviceSuccessfulSubject, + strings.serviceSuccessfulBody, + ) + } + + private sendServiceFailedNotification( + theCase: Case, + ): Promise { + return this.sendEmails( + theCase, + SubpoenaNotificationType.SERVICE_FAILED, + strings.serviceFailedSubject, + strings.serviceFailedBody, + ) + } + + private sendDefendantSelectedDefenderNotification( + theCase: Case, + ): Promise { + return this.sendEmails( + theCase, + SubpoenaNotificationType.DEFENDANT_SELECTED_DEFENDER, + strings.defendantSelectedDefenderSubject, + strings.defendantSelectedDefenderBody, + ) + } + + private sendNotification( + type: SubpoenaNotificationType, + theCase: Case, + ): Promise { + switch (type) { + case SubpoenaNotificationType.SERVICE_SUCCESSFUL: + return this.sendServiceSuccessfulNotification(theCase) + case SubpoenaNotificationType.SERVICE_FAILED: + return this.sendServiceFailedNotification(theCase) + case SubpoenaNotificationType.DEFENDANT_SELECTED_DEFENDER: + return this.sendDefendantSelectedDefenderNotification(theCase) + default: + throw new InternalServerErrorException( + `Invalid notification type: ${type}`, + ) + } } - async sendNotification( - type: NotificationType, - subpoena: Subpoena, + async sendSubpoenaNotification( + type: SubpoenaNotificationType, + theCase: Case, ): Promise { + await this.refreshFormatMessage() + try { - await this.sendSubpoenaNotification( - type as SubpoenaNotificationType, - subpoena, - ) + return await this.sendNotification(type, theCase) } catch (error) { this.logger.error('Failed to send notification', error) return { delivered: false } } - - return { delivered: true } } } diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts b/apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts index 5b4a3f96360e..48abd18bd9b5 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts @@ -24,9 +24,9 @@ import { DefendantService } from '../../defendant' import { eventModuleConfig, EventService } from '../../event' import { InstitutionService } from '../../institution' import { UserService } from '../../user' +import { CaseNotificationService } from '../caseNotification.service' import { InstitutionNotificationService } from '../institutionNotification.service' import { InternalNotificationController } from '../internalNotification.controller' -import { InternalNotificationService } from '../internalNotification.service' import { Notification } from '../models/notification.model' import { notificationModuleConfig } from '../notification.config' import { NotificationController } from '../notification.controller' @@ -99,7 +99,7 @@ export const createTestingNotificationModule = async () => { { provide: InstitutionService, useValue: { getAll: jest.fn() } }, EventService, NotificationService, - InternalNotificationService, + CaseNotificationService, NotificationDispatchService, InstitutionNotificationService, ], diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/dispatchIndictmentsWaitingForConfirmationNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/dispatchIndictmentsWaitingForConfirmationNotifications.spec.ts index 5d8969907626..29e5307c7643 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/dispatchIndictmentsWaitingForConfirmationNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/dispatchIndictmentsWaitingForConfirmationNotifications.spec.ts @@ -2,8 +2,9 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' import { + InstitutionNotificationType, InstitutionType, - NotificationType, + NotificationDispatchType, } from '@island.is/judicial-system/types' import { createTestingNotificationModule } from '../createTestingNotificationModule' @@ -50,7 +51,7 @@ describe('InternalNotificationController - Dispatch indictments waiting for conf await internalNotificationController .dispatchNotification({ - type: NotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION, + type: NotificationDispatchType.INDICTMENTS_WAITING_FOR_CONFIRMATION, }) .then((result) => (then.result = result)) .catch((error) => (then.error = error)) @@ -72,16 +73,16 @@ describe('InternalNotificationController - Dispatch indictments waiting for conf ) expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledWith([ { - type: MessageType.NOTIFICATION, + type: MessageType.INSTITUTION_NOTIFICATION, body: { - type: NotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION, + type: InstitutionNotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION, prosecutorsOfficeId: prosecutorsOfficeId1, }, }, { - type: MessageType.NOTIFICATION, + type: MessageType.INSTITUTION_NOTIFICATION, body: { - type: NotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION, + type: InstitutionNotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION, prosecutorsOfficeId: prosecutorsOfficeId2, }, }, diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts index 097e90d35fa6..2ff2fff6d650 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts @@ -8,9 +8,9 @@ import { DEFENDER_ROUTE, } from '@island.is/judicial-system/consts' import { + CaseNotificationType, CaseType, DateType, - NotificationType, User, } from '@island.is/judicial-system/types' @@ -55,7 +55,7 @@ describe('InternalNotificationController - Send defender assigned notifications' notificationDTO = { user: { id: userId } as User, - type: NotificationType.ADVOCATE_ASSIGNED, + type: CaseNotificationType.ADVOCATE_ASSIGNED, } mockEmailService = emailService diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealCompletedNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealCompletedNotifications.spec.ts index 88b1e6ab7f73..bc9c0a684778 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealCompletedNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealCompletedNotifications.spec.ts @@ -6,9 +6,9 @@ import { ConfigType } from '@island.is/nest/config' import { CaseAppealRulingDecision, CaseDecision, + CaseNotificationType, CaseState, CaseType, - NotificationType, User, } from '@island.is/judicial-system/types' @@ -83,7 +83,7 @@ describe('InternalNotificationController - Send appeal completed notifications', } as Case, { user: { id: userId } as User, - type: NotificationType.APPEAL_COMPLETED, + type: CaseNotificationType.APPEAL_COMPLETED, }, ) .then((result) => (then.result = result)) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealFilesUpdatedNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealFilesUpdatedNotifications.spec.ts index 3d76140d5355..1cc6f4f9e31a 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealFilesUpdatedNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealFilesUpdatedNotifications.spec.ts @@ -3,7 +3,7 @@ import { uuid } from 'uuidv4' import { EmailService } from '@island.is/email-service' import { - NotificationType, + CaseNotificationType, User, UserRole, } from '@island.is/judicial-system/types' @@ -85,7 +85,7 @@ describe('InternalNotificationController - Send appeal case files updated notifi } as Case, { user: { id: userId } as User, - type: NotificationType.APPEAL_CASE_FILES_UPDATED, + type: CaseNotificationType.APPEAL_CASE_FILES_UPDATED, }, ) .then((result) => (then.result = result)) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealJudgesAssignedNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealJudgesAssignedNotifications.spec.ts index 1189a6c2970f..b455d775f174 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealJudgesAssignedNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealJudgesAssignedNotifications.spec.ts @@ -3,7 +3,7 @@ import { uuid } from 'uuidv4' import { EmailService } from '@island.is/email-service' import { - NotificationType, + CaseNotificationType, User, UserRole, } from '@island.is/judicial-system/types' @@ -83,7 +83,7 @@ describe('InternalNotificationController - Send appeal judges assigned notificat } as Case, { user: { id: userId } as User, - type: NotificationType.APPEAL_JUDGES_ASSIGNED, + type: CaseNotificationType.APPEAL_JUDGES_ASSIGNED, }, ) .then((result) => (then.result = result)) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealReceivedByCourtNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealReceivedByCourtNotifications.spec.ts index 37f9dee8a052..27a132aa27a7 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealReceivedByCourtNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealReceivedByCourtNotifications.spec.ts @@ -5,8 +5,8 @@ import { SmsService } from '@island.is/nova-sms' import { formatDate } from '@island.is/judicial-system/formatters' import { + CaseNotificationType, getStatementDeadline, - NotificationType, User, } from '@island.is/judicial-system/types' @@ -70,7 +70,7 @@ describe('InternalNotificationController - Send appeal received by court notific } as Case, { user: { id: userId } as User, - type: NotificationType.APPEAL_RECEIVED_BY_COURT, + type: CaseNotificationType.APPEAL_RECEIVED_BY_COURT, }, ) .then((result) => (then.result = result)) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealStatementNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealStatementNotifications.spec.ts index 7d7bdb6aff13..0f043505f796 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealStatementNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealStatementNotifications.spec.ts @@ -3,8 +3,8 @@ import { uuid } from 'uuidv4' import { EmailService } from '@island.is/email-service' import { + CaseNotificationType, InstitutionType, - NotificationType, User, UserRole, } from '@island.is/judicial-system/types' @@ -78,7 +78,7 @@ describe('InternalNotificationController - Send appeal statement notifications', } as Case, { user, - type: NotificationType.APPEAL_STATEMENT, + type: CaseNotificationType.APPEAL_STATEMENT, }, ) .then((result) => (then.result = result)) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealToCourtOfAppealsNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealToCourtOfAppealsNotifications.spec.ts index 79b89a75a0f3..2119328928c1 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealToCourtOfAppealsNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealToCourtOfAppealsNotifications.spec.ts @@ -4,8 +4,8 @@ import { EmailService } from '@island.is/email-service' import { SmsService } from '@island.is/nova-sms' import { + CaseNotificationType, InstitutionType, - NotificationType, User, UserRole, } from '@island.is/judicial-system/types' @@ -77,7 +77,7 @@ describe('InternalNotificationController - Send appeal to court of appeals notif } as Case, { user, - type: NotificationType.APPEAL_TO_COURT_OF_APPEALS, + type: CaseNotificationType.APPEAL_TO_COURT_OF_APPEALS, }, ) .then((result) => (then.result = result)) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealWithdrawnNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealWithdrawnNotifications.spec.ts index 1d83fc0d0db8..1b2be1516b1e 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealWithdrawnNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAppealWithdrawnNotifications.spec.ts @@ -3,8 +3,8 @@ import { uuid } from 'uuidv4' import { EmailService } from '@island.is/email-service' import { + CaseNotificationType, InstitutionType, - NotificationType, User, UserRole, } from '@island.is/judicial-system/types' @@ -98,7 +98,7 @@ describe('InternalNotificationController - Send appeal withdrawn notifications', role: userRole, institution: { type: InstitutionType.PROSECUTORS_OFFICE }, } as User, - type: NotificationType.APPEAL_WITHDRAWN, + type: CaseNotificationType.APPEAL_WITHDRAWN, }, ) .then((result) => (then.result = result)) @@ -158,7 +158,7 @@ describe('InternalNotificationController - Send appeal withdrawn notifications', then = await givenWhenThen(UserRole.PROSECUTOR, receivedDate, [ { caseId, - type: NotificationType.APPEAL_JUDGES_ASSIGNED, + type: CaseNotificationType.APPEAL_JUDGES_ASSIGNED, } as Notification, ]) }) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendCaseFilesUpdatedNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendCaseFilesUpdatedNotifications.spec.ts index 10102b2743d5..21df0ee723b4 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendCaseFilesUpdatedNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendCaseFilesUpdatedNotifications.spec.ts @@ -3,9 +3,9 @@ import { uuid } from 'uuidv4' import { EmailService } from '@island.is/email-service' import { + CaseNotificationType, CaseType, InstitutionType, - NotificationType, User, UserRole, } from '@island.is/judicial-system/types' @@ -69,7 +69,7 @@ describe('InternalNotificationController - Send case files updated notifications } as Case, { user, - type: NotificationType.CASE_FILES_UPDATED, + type: CaseNotificationType.CASE_FILES_UPDATED, }, ) .then((result) => (then.result = result)) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendCourtDateNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendCourtDateNotifications.spec.ts index a4cb1495e900..18bf5d712b71 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendCourtDateNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendCourtDateNotifications.spec.ts @@ -3,9 +3,9 @@ import { uuid } from 'uuidv4' import { EmailService } from '@island.is/email-service' import { + CaseNotificationType, CaseType, DateType, - NotificationType, User, } from '@island.is/judicial-system/types' @@ -69,7 +69,7 @@ describe('InternalNotificationController - Send court date notifications', () => const notificationDto: CaseNotificationDto = { user: { id: userId } as User, - type: NotificationType.COURT_DATE, + type: CaseNotificationType.COURT_DATE, } const theCase = { @@ -119,7 +119,7 @@ describe('InternalNotificationController - Send court date notifications', () => const notificationDto: CaseNotificationDto = { user: { id: userId } as User, - type: NotificationType.COURT_DATE, + type: CaseNotificationType.COURT_DATE, } const theCase = { @@ -142,7 +142,7 @@ describe('InternalNotificationController - Send court date notifications', () => notifications: [ { caseId, - type: NotificationType.READY_FOR_COURT, + type: CaseNotificationType.READY_FOR_COURT, recipients: [{ address: defenderEmail, success: true }], }, ], @@ -168,7 +168,7 @@ describe('InternalNotificationController - Send court date notifications', () => const notificationDto: CaseNotificationDto = { user: { id: userId } as User, - type: NotificationType.COURT_DATE, + type: CaseNotificationType.COURT_DATE, } const courtDate = new Date(2024, 4, 2, 14, 32) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendDefendantsNotUpdatedAtCourtNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendDefendantsNotUpdatedAtCourtNotifications.spec.ts index facc5b0938f8..b7090ce986dc 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendDefendantsNotUpdatedAtCourtNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendDefendantsNotUpdatedAtCourtNotifications.spec.ts @@ -2,7 +2,7 @@ import { uuid } from 'uuidv4' import { EmailService } from '@island.is/email-service' -import { NotificationType, User } from '@island.is/judicial-system/types' +import { CaseNotificationType, User } from '@island.is/judicial-system/types' import { createTestingNotificationModule } from '../createTestingNotificationModule' @@ -25,7 +25,7 @@ describe('InternalNotificationController - Send defendants not updated at court const userId = uuid() const notificationDto: CaseNotificationDto = { user: { id: userId } as User, - type: NotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT, + type: CaseNotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT, } const caseId = uuid() const courtCaseNumber = uuid() @@ -91,7 +91,7 @@ describe('InternalNotificationController - Send defendants not updated at court ...theCase, notifications: [ { - type: NotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT, + type: CaseNotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT, recipients: [{ address: registrarEmail, success: true }], }, ], diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendHeadsUpNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendHeadsUpNotifications.spec.ts index fbe44ca58ae0..aa3ea50c09ef 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendHeadsUpNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendHeadsUpNotifications.spec.ts @@ -3,8 +3,8 @@ import { uuid } from 'uuidv4' import { SmsService } from '@island.is/nova-sms' import { + CaseNotificationType, CaseType, - NotificationType, User, } from '@island.is/judicial-system/types' @@ -42,7 +42,7 @@ describe('InternalNotificationController - Send heads up notifications', () => { await internalNotificationController .sendCaseNotification(caseId, theCase, { user: { id: userId } as User, - type: NotificationType.HEADS_UP, + type: CaseNotificationType.HEADS_UP, }) .then((result) => (then.result = result)) .catch((error) => (then.error = error)) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentDeniedNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentDeniedNotifications.spec.ts index ca323d3b931d..904b873650f9 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentDeniedNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentDeniedNotifications.spec.ts @@ -3,8 +3,8 @@ import { uuid } from 'uuidv4' import { EmailService } from '@island.is/email-service' import { + CaseNotificationType, CaseType, - NotificationType, User, } from '@island.is/judicial-system/types' @@ -62,7 +62,7 @@ describe('InternalNotificationController - Send indictment denied notification', const notificationDto: CaseNotificationDto = { user: { id: userId } as User, - type: NotificationType.INDICTMENT_DENIED, + type: CaseNotificationType.INDICTMENT_DENIED, } const theCase = { diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentReturnedNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentReturnedNotifications.spec.ts index 1df78d523ff2..24a9ddba4558 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentReturnedNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentReturnedNotifications.spec.ts @@ -3,8 +3,8 @@ import { uuid } from 'uuidv4' import { EmailService } from '@island.is/email-service' import { + CaseNotificationType, CaseType, - NotificationType, User, } from '@island.is/judicial-system/types' @@ -63,7 +63,7 @@ describe('InternalNotificationController - Send indictment returned notification const notificationDto: CaseNotificationDto = { user: { id: userId } as User, - type: NotificationType.INDICTMENT_RETURNED, + type: CaseNotificationType.INDICTMENT_RETURNED, } const theCase = { diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentsWaitingForConfirmationNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentsWaitingForConfirmationNotifications.spec.ts index 66ad10f5af16..d3992015ded4 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentsWaitingForConfirmationNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentsWaitingForConfirmationNotifications.spec.ts @@ -2,7 +2,7 @@ import { uuid } from 'uuidv4' import { EmailService } from '@island.is/email-service' -import { NotificationType } from '@island.is/judicial-system/types' +import { InstitutionNotificationType } from '@island.is/judicial-system/types' import { createTestingNotificationModule } from '../createTestingNotificationModule' @@ -57,7 +57,7 @@ describe('InternalNotificationController - Send indictments waiting for confirma await internalNotificationController .sendNotification({ - type: NotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION, + type: InstitutionNotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION, prosecutorsOfficeId, }) .then((result) => (then.result = result)) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendReadyForCourtNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendReadyForCourtNotifications.spec.ts index b62e0a37a8cb..e1b3b2c1a4c6 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendReadyForCourtNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendReadyForCourtNotifications.spec.ts @@ -10,11 +10,11 @@ import { RESTRICTION_CASE_OVERVIEW_ROUTE, } from '@island.is/judicial-system/consts' import { + CaseNotificationType, CaseState, CaseType, DateType, IndictmentSubtype, - NotificationType, RequestSharedWithDefender, User, } from '@island.is/judicial-system/types' @@ -67,7 +67,7 @@ describe('InternalNotificationController - Send ready for court notifications fo } as Case const notificationDto = { user: { id: userId } as User, - type: NotificationType.READY_FOR_COURT, + type: CaseNotificationType.READY_FOR_COURT, } const courtMobileNumber = uuid() @@ -148,7 +148,7 @@ describe('InternalNotificationController - Send ready for court notifications fo notifications: [ { caseId, - type: NotificationType.READY_FOR_COURT, + type: CaseNotificationType.READY_FOR_COURT, recipients: [ { address: @@ -224,7 +224,7 @@ describe('InternalNotificationController - Send ready for court notifications fo ...theCase, notifications: [ { - type: NotificationType.READY_FOR_COURT, + type: CaseNotificationType.READY_FOR_COURT, recipients: [{ address: 'saul@dummy.is', success: true }], }, ], @@ -261,7 +261,7 @@ describe('InternalNotificationController - Send ready for court notifications fo const courtEmail = uuid() const notificationDto = { user: { id: userId } as User, - type: NotificationType.READY_FOR_COURT, + type: CaseNotificationType.READY_FOR_COURT, } let mockEmailService: EmailService @@ -336,7 +336,7 @@ describe('InternalNotificationController - Send ready for court notifications fo ) expect(mockNotificationModel.create).toHaveBeenCalledWith({ caseId, - type: NotificationType.READY_FOR_COURT, + type: CaseNotificationType.READY_FOR_COURT, recipients: [{ success: true, address: courtEmail }] as Recipient[], }) }) @@ -390,7 +390,7 @@ describe('InternalNotificationController - Send ready for court notifications fo ) expect(mockNotificationModel.create).toHaveBeenCalledWith({ caseId, - type: NotificationType.READY_FOR_COURT, + type: CaseNotificationType.READY_FOR_COURT, recipients: [{ success: true, address: courtEmail }] as Recipient[], }) }) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRevokedNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRevokedNotifications.spec.ts index e3fa4776f5e6..c585586d5c1d 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRevokedNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRevokedNotifications.spec.ts @@ -2,7 +2,7 @@ import { uuid } from 'uuidv4' import { EmailService } from '@island.is/email-service' -import { NotificationType } from '@island.is/judicial-system/types' +import { CaseNotificationType } from '@island.is/judicial-system/types' import { createTestingNotificationModule } from '../createTestingNotificationModule' @@ -58,7 +58,7 @@ describe('InternalNotificationController - Send revoked notifications for indict .sendCaseNotification( theCase.id, { ...theCase, notifications } as Case, - { type: NotificationType.REVOKED } as CaseNotificationDto, + { type: CaseNotificationType.REVOKED } as CaseNotificationDto, ) .then((result) => (then.result = result)) .catch((error) => (then.error = error)) @@ -73,7 +73,7 @@ describe('InternalNotificationController - Send revoked notifications for indict beforeEach(async () => { then = await givenWhenThen([ { - type: NotificationType.COURT_DATE, + type: CaseNotificationType.COURT_DATE, recipients: [{ address: defenderEmail, success: true }], } as Notification, ]) @@ -103,7 +103,7 @@ describe('InternalNotificationController - Send revoked notifications for indict ) expect(mockNotificationModel.create).toHaveBeenCalledWith({ caseId: caseId, - type: NotificationType.REVOKED, + type: CaseNotificationType.REVOKED, recipients: [ { address: judgeEmail, success: true }, { address: registrarEmail, success: true }, diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRulingNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRulingNotifications.spec.ts index d6351b07b9f6..26ccba06fa36 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRulingNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRulingNotifications.spec.ts @@ -10,9 +10,9 @@ import { import { CaseDecision, CaseIndictmentRulingDecision, + CaseNotificationType, CaseState, CaseType, - NotificationType, User, } from '@island.is/judicial-system/types' @@ -41,7 +41,7 @@ describe('InternalNotificationController - Send ruling notifications', () => { const userId = uuid() const notificationDto: CaseNotificationDto = { user: { id: userId } as User, - type: NotificationType.RULING, + type: CaseNotificationType.RULING, } let mockEmailService: EmailService diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAdvocateAssignedNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAdvocateAssignedNotifications.spec.ts index acc19f13a96f..cafbb94353d4 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAdvocateAssignedNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAdvocateAssignedNotifications.spec.ts @@ -1,7 +1,7 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' -import { NotificationType, User } from '@island.is/judicial-system/types' +import { CaseNotificationType, User } from '@island.is/judicial-system/types' import { createTestingNotificationModule } from '../createTestingNotificationModule' @@ -39,7 +39,7 @@ describe('NotificationController - Send advocate assigned notification', () => { await notificationController .sendCaseNotification(caseId, user, { id: caseId } as Case, { - type: NotificationType.ADVOCATE_ASSIGNED, + type: CaseNotificationType.ADVOCATE_ASSIGNED, }) .then((result) => (then.result = result)) .catch((error) => (then.error = error)) @@ -61,7 +61,7 @@ describe('NotificationController - Send advocate assigned notification', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.ADVOCATE_ASSIGNED }, + body: { type: CaseNotificationType.ADVOCATE_ASSIGNED }, }, ]) expect(then.result).toEqual({ notificationSent: true }) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAppealFilesUpdatedNotification.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAppealFilesUpdatedNotification.spec.ts index 3b8b3d3bce51..031f954728fd 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAppealFilesUpdatedNotification.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAppealFilesUpdatedNotification.spec.ts @@ -1,7 +1,7 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' -import { NotificationType, User } from '@island.is/judicial-system/types' +import { CaseNotificationType, User } from '@island.is/judicial-system/types' import { createTestingNotificationModule } from '../createTestingNotificationModule' @@ -39,7 +39,7 @@ describe('NotificationController - Send appeal files updated notifications', () await notificationController .sendCaseNotification(caseId, user, { id: caseId } as Case, { - type: NotificationType.APPEAL_CASE_FILES_UPDATED, + type: CaseNotificationType.APPEAL_CASE_FILES_UPDATED, }) .then((result) => (then.result = result)) .catch((error) => (then.error = error)) @@ -61,7 +61,7 @@ describe('NotificationController - Send appeal files updated notifications', () type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.APPEAL_CASE_FILES_UPDATED }, + body: { type: CaseNotificationType.APPEAL_CASE_FILES_UPDATED }, }, ]) expect(then.result).toEqual({ notificationSent: true }) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAppealJudgesAssignedNotification.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAppealJudgesAssignedNotification.spec.ts index 72fbf6b6b954..92b7878dadde 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAppealJudgesAssignedNotification.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendAppealJudgesAssignedNotification.spec.ts @@ -1,7 +1,7 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' -import { NotificationType, User } from '@island.is/judicial-system/types' +import { CaseNotificationType, User } from '@island.is/judicial-system/types' import { createTestingNotificationModule } from '../createTestingNotificationModule' @@ -39,7 +39,7 @@ describe('NotificationController - Send appeal judges assigned notification', () await notificationController .sendCaseNotification(caseId, user, { id: caseId } as Case, { - type: NotificationType.APPEAL_JUDGES_ASSIGNED, + type: CaseNotificationType.APPEAL_JUDGES_ASSIGNED, }) .then((result) => (then.result = result)) .catch((error) => (then.error = error)) @@ -61,7 +61,7 @@ describe('NotificationController - Send appeal judges assigned notification', () type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.APPEAL_JUDGES_ASSIGNED }, + body: { type: CaseNotificationType.APPEAL_JUDGES_ASSIGNED }, }, ]) expect(then.result).toEqual({ notificationSent: true }) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendCaseFilesUpdatedNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendCaseFilesUpdatedNotifications.spec.ts index d2ace5bc1743..d84062329fb8 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendCaseFilesUpdatedNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendCaseFilesUpdatedNotifications.spec.ts @@ -1,7 +1,7 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' -import { NotificationType, User } from '@island.is/judicial-system/types' +import { CaseNotificationType, User } from '@island.is/judicial-system/types' import { createTestingNotificationModule } from '../createTestingNotificationModule' @@ -37,7 +37,7 @@ describe('NotificationController - Send case files updated notification', () => await notificationController .sendCaseNotification(caseId, user, { id: caseId } as Case, { - type: NotificationType.CASE_FILES_UPDATED, + type: CaseNotificationType.CASE_FILES_UPDATED, }) .then((result) => (then.result = result)) .catch((error) => (then.error = error)) @@ -60,7 +60,7 @@ describe('NotificationController - Send case files updated notification', () => type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.CASE_FILES_UPDATED }, + body: { type: CaseNotificationType.CASE_FILES_UPDATED }, }, ]) expect(then.result).toEqual({ notificationSent: true }) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendCourtDateNotification.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendCourtDateNotification.spec.ts index 180b8de0934e..7d2d2e3b5d8d 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendCourtDateNotification.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendCourtDateNotification.spec.ts @@ -1,7 +1,7 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' -import { NotificationType, User } from '@island.is/judicial-system/types' +import { CaseNotificationType, User } from '@island.is/judicial-system/types' import { createTestingNotificationModule } from '../createTestingNotificationModule' @@ -37,7 +37,7 @@ describe('NotificationController - Send court date notification', () => { await notificationController .sendCaseNotification(caseId, user, { id: caseId } as Case, { - type: NotificationType.COURT_DATE, + type: CaseNotificationType.COURT_DATE, eventOnly, }) .then((result) => (then.result = result)) @@ -61,7 +61,7 @@ describe('NotificationController - Send court date notification', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.COURT_DATE }, + body: { type: CaseNotificationType.COURT_DATE }, }, ]) expect(then.result).toEqual({ notificationSent: true }) @@ -82,7 +82,7 @@ describe('NotificationController - Send court date notification', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.ADVOCATE_ASSIGNED }, + body: { type: CaseNotificationType.ADVOCATE_ASSIGNED }, }, ]) expect(then.result).toEqual({ notificationSent: true }) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendHeadsUpNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendHeadsUpNotifications.spec.ts index a9022a7a3848..3ec53244974d 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendHeadsUpNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendHeadsUpNotifications.spec.ts @@ -1,7 +1,7 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' -import { NotificationType, User } from '@island.is/judicial-system/types' +import { CaseNotificationType, User } from '@island.is/judicial-system/types' import { createTestingNotificationModule } from '../createTestingNotificationModule' @@ -37,7 +37,7 @@ describe('NotificationController - Send heads up notification', () => { await notificationController .sendCaseNotification(caseId, user, { id: caseId } as Case, { - type: NotificationType.HEADS_UP, + type: CaseNotificationType.HEADS_UP, }) .then((result) => (then.result = result)) .catch((error) => (then.error = error)) @@ -60,7 +60,7 @@ describe('NotificationController - Send heads up notification', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.HEADS_UP }, + body: { type: CaseNotificationType.HEADS_UP }, }, ]) expect(then.result).toEqual({ notificationSent: true }) diff --git a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendReadyForCourtNotifications.spec.ts b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendReadyForCourtNotifications.spec.ts index 3a139752beed..9393a39e1b71 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendReadyForCourtNotifications.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendReadyForCourtNotifications.spec.ts @@ -2,8 +2,8 @@ import { uuid } from 'uuidv4' import { MessageService, MessageType } from '@island.is/judicial-system/message' import { + CaseNotificationType, CaseState, - NotificationType, User, } from '@island.is/judicial-system/types' @@ -41,7 +41,7 @@ describe('NotificationController - Send ready for court notification', () => { await notificationController .sendCaseNotification(theCase.id, user, theCase, { - type: NotificationType.READY_FOR_COURT, + type: CaseNotificationType.READY_FOR_COURT, }) .then((result) => (then.result = result)) .catch((error) => (then.error = error)) @@ -64,7 +64,7 @@ describe('NotificationController - Send ready for court notification', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.READY_FOR_COURT }, + body: { type: CaseNotificationType.READY_FOR_COURT }, }, ]) expect(then.result).toEqual({ notificationSent: true }) @@ -88,7 +88,7 @@ describe('NotificationController - Send ready for court notification', () => { type: MessageType.NOTIFICATION, user, caseId, - body: { type: NotificationType.READY_FOR_COURT }, + body: { type: CaseNotificationType.READY_FOR_COURT }, }, { type: MessageType.DELIVERY_TO_COURT_REQUEST, user, caseId }, ]) diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/index.ts b/apps/judicial-system/backend/src/app/modules/subpoena/index.ts index 828b617f4f30..ff1ebda2cebc 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/index.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/index.ts @@ -1,2 +1,3 @@ export { SubpoenaService } from './subpoena.service' export { Subpoena } from './models/subpoena.model' +export { SubpoenaExistsGuard } from './guards/subpoenaExists.guard' diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.controller.ts b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.controller.ts index 7d8b64a24333..da84d9c66c59 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.controller.ts @@ -42,7 +42,10 @@ import { Defendant } from '../defendant' import { CurrentDefendant } from '../defendant/guards/defendant.decorator' import { DefendantExistsGuard } from '../defendant/guards/defendantExists.guard' import { CurrentSubpoena } from './guards/subpoena.decorator' -import { SubpoenaExistsOptionalGuard } from './guards/subpoenaExists.guard' +import { + SubpoenaExistsGuard, + SubpoenaExistsOptionalGuard, +} from './guards/subpoenaExists.guard' import { Subpoena } from './models/subpoena.model' @UseGuards( @@ -52,12 +55,8 @@ import { Subpoena } from './models/subpoena.model' new CaseTypeGuard(indictmentCases), CaseReadGuard, DefendantExistsGuard, - SubpoenaExistsOptionalGuard, ) -@Controller([ - 'api/case/:caseId/defendant/:defendantId/subpoena', - 'api/case/:caseId/defendant/:defendantId/subpoena/:subpoenaId', -]) +@Controller('api/case/:caseId/defendant/:defendantId/subpoena') @ApiTags('subpoenas') export class SubpoenaController { constructor( @@ -73,7 +72,8 @@ export class SubpoenaController { districtCourtRegistrarRule, districtCourtAssistantRule, ) - @Get() + @Get(['', ':subpoenaId']) + @UseGuards(SubpoenaExistsOptionalGuard) @Header('Content-Type', 'application/pdf') @ApiOkResponse({ content: { 'application/pdf': {} }, @@ -117,7 +117,8 @@ export class SubpoenaController { districtCourtRegistrarRule, districtCourtAssistantRule, ) - @Get('serviceCertificate') + @Get(':subpoenaId/serviceCertificate') + @UseGuards(SubpoenaExistsGuard) @Header('Content-Type', 'application/pdf') @ApiOkResponse({ content: { 'application/pdf': {} }, @@ -130,17 +131,13 @@ export class SubpoenaController { @Param('subpoenaId') subpoenaId: string, @CurrentCase() theCase: Case, @CurrentDefendant() defendant: Defendant, + @CurrentSubpoena() subpoena: Subpoena, @Res() res: Response, - @CurrentSubpoena() subpoena?: Subpoena, ): Promise { this.logger.debug( `Getting service certificate for defendant ${defendantId} in subpoena ${subpoenaId} of case ${caseId} as a pdf document`, ) - if (!subpoena) { - throw new InternalServerErrorException('Missing subpoena') - } - const pdf = await this.pdfService.getServiceCertificatePdf( theCase, defendant, diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts index 4b0b3e129d2c..a77e85378765 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts @@ -14,15 +14,19 @@ import { InjectConnection, InjectModel } from '@nestjs/sequelize' import type { Logger } from '@island.is/logging' import { LOGGER_PROVIDER } from '@island.is/logging' -import { MessageService, MessageType } from '@island.is/judicial-system/message' +import { + Message, + MessageService, + MessageType, +} from '@island.is/judicial-system/message' import { CaseFileCategory, DefenderChoice, - isDistrictCourtUser, isFailedServiceStatus, isSuccessfulServiceStatus, isTrafficViolationCase, - NotificationType, + ServiceStatus, + SubpoenaNotificationType, type User as TUser, } from '@island.is/judicial-system/types' @@ -53,6 +57,7 @@ export const include: Includeable[] = [ }, { model: Defendant, as: 'defendant' }, ] + @Injectable() export class SubpoenaService { constructor( @@ -102,6 +107,58 @@ export class SubpoenaService { } } + private async addMessagesForSubpoenaUpdateToQueue( + subpoena: Subpoena, + serviceStatus?: ServiceStatus, + defenderChoice?: DefenderChoice, + defenderNationalId?: string, + ): Promise { + const messages: Message[] = [] + + if (serviceStatus && serviceStatus !== subpoena.serviceStatus) { + if (isSuccessfulServiceStatus(serviceStatus)) { + messages.push({ + type: MessageType.SUBPOENA_NOTIFICATION, + caseId: subpoena.caseId, + elementId: [subpoena.defendantId, subpoena.id], + body: { + type: SubpoenaNotificationType.SERVICE_SUCCESSFUL, + }, + }) + } else if (isFailedServiceStatus(serviceStatus)) { + messages.push({ + type: MessageType.SUBPOENA_NOTIFICATION, + caseId: subpoena.caseId, + elementId: [subpoena.defendantId, subpoena.id], + body: { + type: SubpoenaNotificationType.SERVICE_FAILED, + }, + }) + } + } + + if ( + defenderChoice === DefenderChoice.CHOOSE && + (defenderChoice !== subpoena.defendant?.defenderChoice || + defenderNationalId !== subpoena.defendant?.defenderNationalId) + ) { + messages.push({ + type: MessageType.SUBPOENA_NOTIFICATION, + caseId: subpoena.caseId, + elementId: [subpoena.defendantId, subpoena.id], + body: { + type: SubpoenaNotificationType.DEFENDANT_SELECTED_DEFENDER, + }, + }) + } + + if (messages.length === 0) { + return + } + + return this.messageService.sendMessagesToQueue(messages) + } + async update( subpoena: Subpoena, update: UpdateSubpoenaDto, @@ -119,29 +176,18 @@ export class SubpoenaService { requestedDefenderName, } = update - const notificationType = isSuccessfulServiceStatus(serviceStatus) - ? NotificationType.SERVICE_SUCCESSFUL - : isFailedServiceStatus(serviceStatus) - ? NotificationType.SERVICE_FAILED - : defenderChoice === DefenderChoice.CHOOSE && defenderNationalId - ? NotificationType.DEFENDANT_SELECTED_DEFENDER - : undefined - const [numberOfAffectedRows] = await this.subpoenaModel.update(update, { where: { subpoenaId: subpoena.subpoenaId }, returning: true, transaction, }) - let defenderAffectedRows = 0 - // If there is a change in the defender choice after the judge has confirmed the choice, - // we need to set the isDefenderChoiceConfirmed to false - const isChangingDefenderChoice = - (update.defenderChoice && - subpoena.defendant?.defenderChoice !== update.defenderChoice) || - (update.defenderNationalId && - subpoena.defendant?.defenderNationalId !== update.defenderNationalId && - subpoena.defendant?.isDefenderChoiceConfirmed) + if (numberOfAffectedRows > 1) { + // Tolerate failure, but log error + this.logger.error( + `Unexpected number of rows ${numberOfAffectedRows} affected when updating subpoena`, + ) + } if ( defenderChoice || @@ -149,6 +195,15 @@ export class SubpoenaService { requestedDefenderChoice || requestedDefenderNationalId ) { + // If there is a change in the defender choice after the judge has confirmed the choice, + // we need to set the isDefenderChoiceConfirmed to false + const isChangingDefenderChoice = + (defenderChoice && + subpoena.defendant?.defenderChoice !== defenderChoice) || + (defenderNationalId && + subpoena.defendant?.defenderNationalId !== defenderNationalId && + subpoena.defendant?.isDefenderChoiceConfirmed) + const defendantUpdate: Partial = { defenderChoice, defenderNationalId, @@ -161,7 +216,7 @@ export class SubpoenaService { isDefenderChoiceConfirmed: isChangingDefenderChoice ? false : undefined, } - const [defenderUpdateAffectedRows] = await this.defendantModel.update( + const [numberOfAffectedRows] = await this.defendantModel.update( defendantUpdate, { where: { id: subpoena.defendantId }, @@ -169,35 +224,23 @@ export class SubpoenaService { }, ) - defenderAffectedRows = defenderUpdateAffectedRows - } - - if (numberOfAffectedRows < 1 && defenderAffectedRows < 1) { - this.logger.error( - `Unexpected number of rows ${numberOfAffectedRows} affected when updating subpoena`, - ) - } - - if (notificationType) { - this.messageService - .sendMessagesToQueue([ - { - type: MessageType.SUBPOENA_NOTIFICATION, - body: { - type: notificationType, - subpoena, - }, - }, - ]) - .catch((reason) => - // Tolerate failure, but log - this.logger.error('Failed to dispatch notifications', { reason }), + if (numberOfAffectedRows > 1) { + // Tolerate failure, but log error + this.logger.error( + `Unexpected number of rows ${numberOfAffectedRows} affected when updating defendant`, ) + } } - const updatedSubpoena = await this.findBySubpoenaId(subpoena.subpoenaId) + // No need to wait for this to finish + this.addMessagesForSubpoenaUpdateToQueue( + subpoena, + serviceStatus, + defenderChoice, + defenderNationalId, + ) - return updatedSubpoena + return this.findBySubpoenaId(subpoena.subpoenaId) } async findBySubpoenaId(subpoenaId?: string): Promise { @@ -272,7 +315,7 @@ export class SubpoenaService { { where: { id: subpoena.id } }, ) - if (numberOfAffectedRows < 1) { + if (numberOfAffectedRows !== 1) { this.logger.error( `Unexpected number of rows (${numberOfAffectedRows}) affected when updating subpoena for subpoena ${subpoena.id}`, ) @@ -285,9 +328,11 @@ export class SubpoenaService { 'Failed to deliver subpoena to police due to lack of implementation', error, ) + return { delivered: true } } else { this.logger.error('Error delivering subpoena to police', error) + return { delivered: false } } } diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdfGuards.spec.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdfGuards.spec.ts new file mode 100644 index 000000000000..085cc4d55b71 --- /dev/null +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdfGuards.spec.ts @@ -0,0 +1,19 @@ +import { SubpoenaExistsOptionalGuard } from '../../guards/subpoenaExists.guard' +import { SubpoenaController } from '../../subpoena.controller' + +describe('SubpoenaController - Get subpoena pdf guards', () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let guards: any[] + + beforeEach(() => { + guards = Reflect.getMetadata( + '__guards__', + SubpoenaController.prototype.getSubpoenaPdf, + ) + }) + + it('should have the right guard configuration', () => { + expect(guards).toHaveLength(1) + expect(new guards[0]()).toBeInstanceOf(SubpoenaExistsOptionalGuard) + }) +}) diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/subpoenaControllerGuards.spec.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/subpoenaControllerGuards.spec.ts index 966a64fecfef..deabdae6054f 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/subpoenaControllerGuards.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/subpoenaControllerGuards.spec.ts @@ -2,8 +2,7 @@ import { JwtAuthGuard, RolesGuard } from '@island.is/judicial-system/auth' import { indictmentCases } from '@island.is/judicial-system/types' import { CaseExistsGuard, CaseReadGuard, CaseTypeGuard } from '../../../case' -import { DefendantExistsGuard } from '../../../defendant/guards/defendantExists.guard' -import { SubpoenaExistsOptionalGuard } from '../../guards/subpoenaExists.guard' +import { DefendantExistsGuard } from '../../../defendant' import { SubpoenaController } from '../../subpoena.controller' describe('SubpoenaController - guards', () => { @@ -15,7 +14,7 @@ describe('SubpoenaController - guards', () => { }) it('should have the right guard configuration', () => { - expect(guards).toHaveLength(7) + expect(guards).toHaveLength(6) expect(new guards[0]()).toBeInstanceOf(JwtAuthGuard) expect(new guards[1]()).toBeInstanceOf(RolesGuard) expect(new guards[2]()).toBeInstanceOf(CaseExistsGuard) @@ -25,6 +24,5 @@ describe('SubpoenaController - guards', () => { }) expect(new guards[4]()).toBeInstanceOf(CaseReadGuard) expect(new guards[5]()).toBeInstanceOf(DefendantExistsGuard) - expect(new guards[6]()).toBeInstanceOf(SubpoenaExistsOptionalGuard) }) }) diff --git a/apps/judicial-system/message-handler/src/app/test/handleMessage.spec.ts b/apps/judicial-system/message-handler/src/app/test/handleMessage.spec.ts index 26500faf2b8e..6fd944d6d554 100644 --- a/apps/judicial-system/message-handler/src/app/test/handleMessage.spec.ts +++ b/apps/judicial-system/message-handler/src/app/test/handleMessage.spec.ts @@ -9,7 +9,7 @@ import { MessageService, MessageType, } from '@island.is/judicial-system/message' -import { NotificationType, User } from '@island.is/judicial-system/types' +import { User } from '@island.is/judicial-system/types' import { appModuleConfig } from '../app.config' import { InternalDeliveryService } from '../internalDelivery.service' diff --git a/apps/judicial-system/scheduler/src/app/app.service.ts b/apps/judicial-system/scheduler/src/app/app.service.ts index f16cf5e55c68..015d825af410 100644 --- a/apps/judicial-system/scheduler/src/app/app.service.ts +++ b/apps/judicial-system/scheduler/src/app/app.service.ts @@ -6,7 +6,7 @@ import { type Logger, LOGGER_PROVIDER } from '@island.is/logging' import { type ConfigType } from '@island.is/nest/config' import { MessageService, MessageType } from '@island.is/judicial-system/message' -import { NotificationType } from '@island.is/judicial-system/types' +import { NotificationDispatchType } from '@island.is/judicial-system/types' import { appModuleConfig } from './app.config' import { now } from './date.factory' @@ -33,7 +33,9 @@ export class AppService { .sendMessagesToQueue([ { type: MessageType.NOTIFICATION_DISPATCH, - body: { type: NotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION }, + body: { + type: NotificationDispatchType.INDICTMENTS_WAITING_FOR_CONFIRMATION, + }, }, ]) .catch((reason) => diff --git a/apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql b/apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql index f58b990fc571..06bce52f67c8 100644 --- a/apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql +++ b/apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql @@ -41,6 +41,13 @@ query LimitedAccessCase($input: CaseQueryInput!) { subpoenas { id created + serviceStatus + serviceDate + servedBy + comment + defenderNationalId + caseId + subpoenaId } } defenderName diff --git a/apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx b/apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx index 32374c38270f..7e1dd48f65b8 100644 --- a/apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx +++ b/apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx @@ -19,7 +19,7 @@ import { PageLayout, PageTitle, ServiceAnnouncement, - useIndictmentsLawsBroken, + // useIndictmentsLawsBroken, NOTE: Temporarily hidden while list of laws broken is not complete } from '@island.is/judicial-system-web/src/components' import { IndictmentDecision } from '@island.is/judicial-system-web/src/graphql/schema' import { useDefendants } from '@island.is/judicial-system-web/src/utils/hooks' @@ -35,7 +35,7 @@ const IndictmentOverview = () => { const { updateDefendantState, updateDefendant } = useDefendants() const { formatMessage } = useIntl() - const lawsBroken = useIndictmentsLawsBroken(workingCase) + // const lawsBroken = useIndictmentsLawsBroken(workingCase) NOTE: Temporarily hidden while list of laws broken is not complete const [modalVisible, setModalVisible] = useState<'RETURN_INDICTMENT'>() const latestDate = workingCase.courtDate ?? workingCase.arraignmentDate diff --git a/apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx b/apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx index bc07f49331d6..9fa89eb677ca 100644 --- a/apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx +++ b/apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx @@ -103,9 +103,11 @@ const Subpoena: FC = () => { }, [ isSchedulingArraignmentDate, - sendCourtDateToServer, workingCase.defendants, + workingCase.indictmentDecision, workingCase.id, + isArraignmentScheduled, + sendCourtDateToServer, updateDefendant, ], ) diff --git a/apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx b/apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx index 1bc7c916329f..5bc841c71ab6 100644 --- a/apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx +++ b/apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx @@ -20,7 +20,7 @@ import { PageLayout, PageTitle, SectionHeading, - useIndictmentsLawsBroken, + // useIndictmentsLawsBroken, NOTE: Temporarily hidden while list of laws broken is not complete UserContext, } from '@island.is/judicial-system-web/src/components' import { useProsecutorSelectionUsersQuery } from '@island.is/judicial-system-web/src/components/ProsecutorSelection/prosecutorSelectionUsers.generated' @@ -55,7 +55,7 @@ export const Overview = () => { const [selectedIndictmentReviewer, setSelectedIndictmentReviewer] = useState | null>() const [modalVisible, setModalVisible] = useState() - const lawsBroken = useIndictmentsLawsBroken(workingCase) + // const lawsBroken = useIndictmentsLawsBroken(workingCase) NOTE: Temporarily hidden while list of laws broken is not complete const [selectedDefendant, setSelectedDefendant] = useState() const { setAndSendDefendantToServer } = useDefendants() diff --git a/libs/judicial-system/auth/src/lib/guards/roles.guard.ts b/libs/judicial-system/auth/src/lib/guards/roles.guard.ts index e2305ac4dac6..74fb865dba1d 100644 --- a/libs/judicial-system/auth/src/lib/guards/roles.guard.ts +++ b/libs/judicial-system/auth/src/lib/guards/roles.guard.ts @@ -37,6 +37,7 @@ export class RolesGuard implements CanActivate { if (!rule) { return false } + // Allow if the rule is simply a user role if (typeof rule === 'string') { return true diff --git a/libs/judicial-system/message/src/lib/message.ts b/libs/judicial-system/message/src/lib/message.ts index 2cdc08ea958e..e68dbc39c93e 100644 --- a/libs/judicial-system/message/src/lib/message.ts +++ b/libs/judicial-system/message/src/lib/message.ts @@ -27,6 +27,7 @@ export enum MessageType { DELIVERY_TO_POLICE_APPEAL = 'DELIVERY_TO_POLICE_APPEAL', NOTIFICATION = 'NOTIFICATION', SUBPOENA_NOTIFICATION = 'SUBPOENA_NOTIFICATION', + INSTITUTION_NOTIFICATION = 'INSTITUTION_NOTIFICATION', NOTIFICATION_DISPATCH = 'NOTIFICATION_DISPATCH', } @@ -61,6 +62,7 @@ export const messageEndpoint: { [key in MessageType]: string } = { DELIVERY_TO_POLICE_APPEAL: 'deliverAppealToPolice', NOTIFICATION: 'notification', SUBPOENA_NOTIFICATION: 'subpoenaNotification', + INSTITUTION_NOTIFICATION: 'institutionNotification', NOTIFICATION_DISPATCH: 'notification/dispatch', } diff --git a/libs/judicial-system/types/src/index.ts b/libs/judicial-system/types/src/index.ts index a63b26a41b5a..99ffe104e335 100644 --- a/libs/judicial-system/types/src/index.ts +++ b/libs/judicial-system/types/src/index.ts @@ -11,7 +11,13 @@ export { isFailedServiceStatus, } from './lib/defendant' export { InstitutionType } from './lib/institution' -export { NotificationType } from './lib/notification' +export { + CaseNotificationType, + SubpoenaNotificationType, + NotificationType, + InstitutionNotificationType, + NotificationDispatchType, +} from './lib/notification' export type { Institution } from './lib/institution' export { EventType } from './lib/eventLog' export { DateType } from './lib/dateLog' diff --git a/libs/judicial-system/types/src/lib/notification.ts b/libs/judicial-system/types/src/lib/notification.ts index 410ef203879e..7755fdc19c76 100644 --- a/libs/judicial-system/types/src/lib/notification.ts +++ b/libs/judicial-system/types/src/lib/notification.ts @@ -1,4 +1,4 @@ -export enum NotificationType { +export enum CaseNotificationType { HEADS_UP = 'HEADS_UP', READY_FOR_COURT = 'READY_FOR_COURT', RECEIVED_BY_COURT = 'RECEIVED_BY_COURT', @@ -17,9 +17,44 @@ export enum NotificationType { APPEAL_WITHDRAWN = 'APPEAL_WITHDRAWN', INDICTMENT_DENIED = 'INDICTMENT_DENIED', INDICTMENT_RETURNED = 'INDICTMENT_RETURNED', - INDICTMENTS_WAITING_FOR_CONFIRMATION = 'INDICTMENTS_WAITING_FOR_CONFIRMATION', CASE_FILES_UPDATED = 'CASE_FILES_UPDATED', +} + +export enum SubpoenaNotificationType { SERVICE_SUCCESSFUL = 'SERVICE_SUCCESSFUL', SERVICE_FAILED = 'SERVICE_FAILED', DEFENDANT_SELECTED_DEFENDER = 'DEFENDANT_SELECTED_DEFENDER', } + +export enum NotificationType { + HEADS_UP = CaseNotificationType.HEADS_UP, + READY_FOR_COURT = CaseNotificationType.READY_FOR_COURT, + RECEIVED_BY_COURT = CaseNotificationType.RECEIVED_BY_COURT, + COURT_DATE = CaseNotificationType.COURT_DATE, + RULING = CaseNotificationType.RULING, + MODIFIED = CaseNotificationType.MODIFIED, + REVOKED = CaseNotificationType.REVOKED, + ADVOCATE_ASSIGNED = CaseNotificationType.ADVOCATE_ASSIGNED, + DEFENDANTS_NOT_UPDATED_AT_COURT = CaseNotificationType.DEFENDANTS_NOT_UPDATED_AT_COURT, + APPEAL_TO_COURT_OF_APPEALS = CaseNotificationType.APPEAL_TO_COURT_OF_APPEALS, + APPEAL_RECEIVED_BY_COURT = CaseNotificationType.APPEAL_RECEIVED_BY_COURT, + APPEAL_STATEMENT = CaseNotificationType.APPEAL_STATEMENT, + APPEAL_COMPLETED = CaseNotificationType.APPEAL_COMPLETED, + APPEAL_JUDGES_ASSIGNED = CaseNotificationType.APPEAL_JUDGES_ASSIGNED, + APPEAL_CASE_FILES_UPDATED = CaseNotificationType.APPEAL_CASE_FILES_UPDATED, + APPEAL_WITHDRAWN = CaseNotificationType.APPEAL_WITHDRAWN, + INDICTMENT_DENIED = CaseNotificationType.INDICTMENT_DENIED, + INDICTMENT_RETURNED = CaseNotificationType.INDICTMENT_RETURNED, + CASE_FILES_UPDATED = CaseNotificationType.CASE_FILES_UPDATED, + SERVICE_SUCCESSFUL = SubpoenaNotificationType.SERVICE_SUCCESSFUL, + SERVICE_FAILED = SubpoenaNotificationType.SERVICE_FAILED, + DEFENDANT_SELECTED_DEFENDER = SubpoenaNotificationType.DEFENDANT_SELECTED_DEFENDER, +} + +export enum InstitutionNotificationType { + INDICTMENTS_WAITING_FOR_CONFIRMATION = 'INDICTMENTS_WAITING_FOR_CONFIRMATION', +} + +export enum NotificationDispatchType { + INDICTMENTS_WAITING_FOR_CONFIRMATION = InstitutionNotificationType.INDICTMENTS_WAITING_FOR_CONFIRMATION, +}