From fbc42183e8dbe7387557eb70315472ae989a3319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 6 Dec 2024 14:20:34 +0000 Subject: [PATCH 01/12] Send notifications to court officials --- .../backend/src/app/formatters/formatters.ts | 22 +++++++- .../backend/src/app/formatters/index.ts | 1 + .../backend/src/app/messages/notifications.ts | 15 +++++ .../src/app/modules/case/case.service.ts | 24 ++++++++ .../modules/notification/guards/rolesRules.ts | 12 +++- .../notification/notification.service.ts | 1 + .../caseNotification.service.ts | 56 +++++++++++++++++++ .../types/src/lib/notification.ts | 2 + 8 files changed, 129 insertions(+), 4 deletions(-) diff --git a/apps/judicial-system/backend/src/app/formatters/formatters.ts b/apps/judicial-system/backend/src/app/formatters/formatters.ts index 0f43edf7200b..3f610c0ab1c3 100644 --- a/apps/judicial-system/backend/src/app/formatters/formatters.ts +++ b/apps/judicial-system/backend/src/app/formatters/formatters.ts @@ -1,4 +1,4 @@ -import type { FormatMessage } from '@island.is/cms-translations' +import type { formatMessage, FormatMessage } from '@island.is/cms-translations' import { DEFENDER_INDICTMENT_ROUTE, @@ -262,6 +262,26 @@ export const formatPostponedCourtDateEmailNotification = ( return { subject, body } } +export const formatCourtOfficialAssignedEmailNotification = ( + formatMessage: FormatMessage, + courtCaseNumber?: string, + userRole?: UserRole, + overviewUrl?: string, +) => { + const subject = formatMessage( + notifications.courtOfficialAssignedEmail.subject, + { courtCaseNumber }, + ) + const body = formatMessage(notifications.courtOfficialAssignedEmail.body, { + courtCaseNumber, + role: userRole, + linkStart: ``, + linkEnd: '', + }) + + return { subject, body } +} + export const formatProsecutorCourtDateEmailNotification = ( formatMessage: FormatMessage, type: CaseType, diff --git a/apps/judicial-system/backend/src/app/formatters/index.ts b/apps/judicial-system/backend/src/app/formatters/index.ts index 01d46156bf88..abc4a6331eb3 100644 --- a/apps/judicial-system/backend/src/app/formatters/index.ts +++ b/apps/judicial-system/backend/src/app/formatters/index.ts @@ -11,6 +11,7 @@ export { formatCourtReadyForCourtSmsNotification, formatCourtResubmittedToCourtSmsNotification, formatCourtRevokedSmsNotification, + formatCourtOfficialAssignedEmailNotification, formatDefenderCourtDateEmailNotification, formatDefenderRevokedEmailNotification, formatPrisonAdministrationRulingNotification, diff --git a/apps/judicial-system/backend/src/app/messages/notifications.ts b/apps/judicial-system/backend/src/app/messages/notifications.ts index a7bf8f898acf..eb0378808998 100644 --- a/apps/judicial-system/backend/src/app/messages/notifications.ts +++ b/apps/judicial-system/backend/src/app/messages/notifications.ts @@ -856,4 +856,19 @@ export const notifications = { description: 'Texti í pósti til aðila máls þegar ný gögn eru send', }, }), + courtOfficialAssignedEmail: defineMessages({ + subject: { + id: 'judicial.system.backend:notifications.court_official_assigned_email.subject', + defaultMessage: 'Úthlutun máls {courtCaseNumber}', + description: + 'Fyrirsögn í pósti til dómara og dómritara þegar máli er úthlutað á þau', + }, + body: { + id: 'judicial.system.backend:notifications.court_official_assigned_email.body', + defaultMessage: + 'Héraðsdómur hefur skráð þig sem {role, select, JUDGE {dómara} REGISTRAR {dómritara} other {óþekkt}} í máli {courtCaseNumber}. Hægt er að nálgast gögn málsins á {linkStart}yfirlitssíðu málsins í Réttarvörslugátt{linkEnd}}', + description: + 'Texti í pósti til dómara og dómritara þegar máli er úthlutað á þau', + }, + }), } 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 c89bbc8c0e0c..ee55af281a17 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 @@ -686,6 +686,20 @@ export class CaseService { ]) } + private addMessagesForCourtOfficalAssignedToQueue( + theCase: Case, + user: TUser, + ): Promise { + return this.messageService.sendMessagesToQueue([ + { + type: MessageType.NOTIFICATION, + user, + caseId: theCase.id, + body: { type: CaseNotificationType.COURT_OFFICIAL_ASSIGNED }, + }, + ]) + } + private addMessagesForReceivedCaseToQueue( theCase: Case, user: TUser, @@ -1277,6 +1291,8 @@ export class CaseService { ): Promise { const isIndictment = isIndictmentCase(updatedCase.type) + console.log('!!!!!!!!!!!!!!!!!!!!!!', { isIndictment: updatedCase.state }) + if (updatedCase.state !== theCase.state) { // New case state if ( @@ -1440,12 +1456,20 @@ export class CaseService { const courtDateChanged = updatedCourtDate && updatedCourtDate.date.getTime() !== courtDate?.date.getTime() + const judgeChanged = + updatedCase.judge?.nationalId !== theCase.judge?.nationalId + const registrarChanged = + updatedCase.registrar?.nationalId !== theCase.registrar?.nationalId if (arraignmentDateChanged || courtDateChanged) { // New arraignment date or new court date await this.addMessagesForNewCourtDateToQueue(updatedCase, user) } + if (judgeChanged || registrarChanged) { + await this.addMessagesForCourtOfficalAssignedToQueue(updatedCase, user) + } + await this.addMessagesForNewSubpoenasToQueue(theCase, updatedCase, user) } } 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 04cccc5de218..93bf8a6043bb 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 @@ -28,12 +28,15 @@ export const defenderNotificationRule: RolesRule = { ], } as RolesRule -// Allows district court judges to send notifiications +// Allows district court judges to send notifications export const districtCourtJudgeNotificationRule: RolesRule = { role: UserRole.DISTRICT_COURT_JUDGE, type: RulesType.FIELD_VALUES, dtoField: 'type', - dtoFieldValues: [CaseNotificationType.COURT_DATE], + dtoFieldValues: [ + CaseNotificationType.COURT_DATE, + CaseNotificationType.COURT_OFFICIAL_ASSIGNED, + ], } // Allows district court registrars to send notifications @@ -41,7 +44,10 @@ export const districtCourtRegistrarNotificationRule: RolesRule = { role: UserRole.DISTRICT_COURT_REGISTRAR, type: RulesType.FIELD_VALUES, dtoField: 'type', - dtoFieldValues: [CaseNotificationType.COURT_DATE], + dtoFieldValues: [ + CaseNotificationType.COURT_DATE, + CaseNotificationType.COURT_OFFICIAL_ASSIGNED, + ], } // Allows district court assistants to send notifications 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 7801234f9ae6..a281e586f06c 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 @@ -78,6 +78,7 @@ export class NotificationService { case CaseNotificationType.APPEAL_JUDGES_ASSIGNED: case CaseNotificationType.APPEAL_CASE_FILES_UPDATED: case CaseNotificationType.CASE_FILES_UPDATED: + case CaseNotificationType.COURT_OFFICIAL_ASSIGNED: messages = [this.getNotificationMessage(type, user, theCase)] break default: diff --git a/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts b/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts index 0c4cbba076cb..bdb6be2808d9 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts @@ -55,6 +55,7 @@ import { formatCourtReadyForCourtSmsNotification, formatCourtResubmittedToCourtSmsNotification, formatCourtRevokedSmsNotification, + formatCourtOfficialAssignedEmailNotification, formatDefenderCourtDateEmailNotification, formatDefenderCourtDateLinkEmailNotification, formatDefenderReadyForCourtEmailNotification, @@ -689,6 +690,34 @@ export class CaseNotificationService extends BaseNotificationService { }) } + private sendCourtOfficialAssignedEmailNotificationForIndictmentCase( + theCase: Case, + overviewUrl?: string, + ): Promise[] { + const promises: Promise[] = [] + console.log('theCase.judge', theCase.judge?.email) + + for (const courtOfficial of [theCase.judge, theCase.registrar]) { + const { subject, body } = formatCourtOfficialAssignedEmailNotification( + this.formatMessage, + theCase.courtCaseNumber, + courtOfficial?.role, + overviewUrl, + ) + + promises.push( + this.sendEmail( + subject, + body, + courtOfficial?.name, + courtOfficial?.email, + ), + ) + } + + return promises + } + private sendCourtDateEmailNotificationForIndictmentCase( theCase: Case, user: User, @@ -810,6 +839,31 @@ export class CaseNotificationService extends BaseNotificationService { return result } + + private async sendCourtOfficialAssignedNotifications( + theCase: Case, + user: User, + ): Promise { + const promises: Promise[] = [] + + if (isIndictmentCase(theCase.type)) { + promises.push( + ...this.sendCourtOfficialAssignedEmailNotificationForIndictmentCase( + theCase, + ), + ) + } + + const recipients = await Promise.all(promises) + + const result = await this.recordNotification( + theCase.id, + CaseNotificationType.COURT_OFFICIAL_ASSIGNED, + recipients, + ) + + return result + } //#endregion //#region RULING notifications @@ -2552,6 +2606,8 @@ export class CaseNotificationService extends BaseNotificationService { return this.sendReceivedByCourtNotifications(theCase) case CaseNotificationType.COURT_DATE: return this.sendCourtDateNotifications(theCase, user) + case CaseNotificationType.COURT_OFFICIAL_ASSIGNED: + return this.sendCourtOfficialAssignedNotifications(theCase, user) case CaseNotificationType.RULING: return this.sendRulingNotifications(theCase) case CaseNotificationType.MODIFIED: diff --git a/libs/judicial-system/types/src/lib/notification.ts b/libs/judicial-system/types/src/lib/notification.ts index e9b8df060e63..f8823a0f77b3 100644 --- a/libs/judicial-system/types/src/lib/notification.ts +++ b/libs/judicial-system/types/src/lib/notification.ts @@ -3,6 +3,7 @@ export enum CaseNotificationType { READY_FOR_COURT = 'READY_FOR_COURT', RECEIVED_BY_COURT = 'RECEIVED_BY_COURT', COURT_DATE = 'COURT_DATE', + COURT_OFFICIAL_ASSIGNED = 'COURT_OFFICIAL_ASSIGNED', RULING = 'RULING', MODIFIED = 'MODIFIED', REVOKED = 'REVOKED', @@ -45,6 +46,7 @@ export enum NotificationType { READY_FOR_COURT = CaseNotificationType.READY_FOR_COURT, RECEIVED_BY_COURT = CaseNotificationType.RECEIVED_BY_COURT, COURT_DATE = CaseNotificationType.COURT_DATE, + COURT_OFFICIAL_ASSIGNED = CaseNotificationType.COURT_OFFICIAL_ASSIGNED, RULING = CaseNotificationType.RULING, MODIFIED = CaseNotificationType.MODIFIED, REVOKED = CaseNotificationType.REVOKED, From 8ecd201ad3817f2dd4eca9b0c99d5a3c8050bc55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 6 Dec 2024 14:33:20 +0000 Subject: [PATCH 02/12] Fix body --- apps/judicial-system/backend/src/app/messages/notifications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/judicial-system/backend/src/app/messages/notifications.ts b/apps/judicial-system/backend/src/app/messages/notifications.ts index eb0378808998..a562e1a482e0 100644 --- a/apps/judicial-system/backend/src/app/messages/notifications.ts +++ b/apps/judicial-system/backend/src/app/messages/notifications.ts @@ -866,7 +866,7 @@ export const notifications = { body: { id: 'judicial.system.backend:notifications.court_official_assigned_email.body', defaultMessage: - 'Héraðsdómur hefur skráð þig sem {role, select, JUDGE {dómara} REGISTRAR {dómritara} other {óþekkt}} í máli {courtCaseNumber}. Hægt er að nálgast gögn málsins á {linkStart}yfirlitssíðu málsins í Réttarvörslugátt{linkEnd}}', + 'Héraðsdómur hefur skráð þig sem {role, select, DISTRICT_COURT_JUDGE {dómara} DISTRICT_COURT_REGISTRAR {dómritara} other {óþekkt}} í máli {courtCaseNumber}. Hægt er að nálgast gögn málsins á {linkStart}yfirlitssíðu málsins í Réttarvörslugátt{linkEnd}', description: 'Texti í pósti til dómara og dómritara þegar máli er úthlutað á þau', }, From 6fb36dbe2fae32d9f290bb12c64e9d6162cc2e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 6 Dec 2024 21:26:48 +0000 Subject: [PATCH 03/12] Send spesific judge notification --- .../backend/src/app/formatters/formatters.ts | 20 ------ .../backend/src/app/formatters/index.ts | 1 - .../src/app/modules/case/case.service.ts | 9 ++- .../modules/notification/guards/rolesRules.ts | 4 +- .../notification/notification.service.ts | 3 +- .../caseNotification.service.ts | 65 +++++++------------ .../types/src/lib/notification.ts | 6 +- 7 files changed, 38 insertions(+), 70 deletions(-) diff --git a/apps/judicial-system/backend/src/app/formatters/formatters.ts b/apps/judicial-system/backend/src/app/formatters/formatters.ts index 3f610c0ab1c3..1bbc13c9446a 100644 --- a/apps/judicial-system/backend/src/app/formatters/formatters.ts +++ b/apps/judicial-system/backend/src/app/formatters/formatters.ts @@ -262,26 +262,6 @@ export const formatPostponedCourtDateEmailNotification = ( return { subject, body } } -export const formatCourtOfficialAssignedEmailNotification = ( - formatMessage: FormatMessage, - courtCaseNumber?: string, - userRole?: UserRole, - overviewUrl?: string, -) => { - const subject = formatMessage( - notifications.courtOfficialAssignedEmail.subject, - { courtCaseNumber }, - ) - const body = formatMessage(notifications.courtOfficialAssignedEmail.body, { - courtCaseNumber, - role: userRole, - linkStart: ``, - linkEnd: '', - }) - - return { subject, body } -} - export const formatProsecutorCourtDateEmailNotification = ( formatMessage: FormatMessage, type: CaseType, diff --git a/apps/judicial-system/backend/src/app/formatters/index.ts b/apps/judicial-system/backend/src/app/formatters/index.ts index abc4a6331eb3..01d46156bf88 100644 --- a/apps/judicial-system/backend/src/app/formatters/index.ts +++ b/apps/judicial-system/backend/src/app/formatters/index.ts @@ -11,7 +11,6 @@ export { formatCourtReadyForCourtSmsNotification, formatCourtResubmittedToCourtSmsNotification, formatCourtRevokedSmsNotification, - formatCourtOfficialAssignedEmailNotification, formatDefenderCourtDateEmailNotification, formatDefenderRevokedEmailNotification, formatPrisonAdministrationRulingNotification, 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 ee55af281a17..17a8ed9d0e2d 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 @@ -686,7 +686,7 @@ export class CaseService { ]) } - private addMessagesForCourtOfficalAssignedToQueue( + private addMessagesForDistrictCourtJudgeAssignedToQueue( theCase: Case, user: TUser, ): Promise { @@ -695,7 +695,7 @@ export class CaseService { type: MessageType.NOTIFICATION, user, caseId: theCase.id, - body: { type: CaseNotificationType.COURT_OFFICIAL_ASSIGNED }, + body: { type: CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED }, }, ]) } @@ -1467,7 +1467,10 @@ export class CaseService { } if (judgeChanged || registrarChanged) { - await this.addMessagesForCourtOfficalAssignedToQueue(updatedCase, user) + await this.addMessagesForDistrictCourtJudgeAssignedToQueue( + updatedCase, + user, + ) } await this.addMessagesForNewSubpoenasToQueue(theCase, updatedCase, user) 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 93bf8a6043bb..d21b142b0ea8 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 @@ -35,7 +35,7 @@ export const districtCourtJudgeNotificationRule: RolesRule = { dtoField: 'type', dtoFieldValues: [ CaseNotificationType.COURT_DATE, - CaseNotificationType.COURT_OFFICIAL_ASSIGNED, + CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED, ], } @@ -46,7 +46,7 @@ export const districtCourtRegistrarNotificationRule: RolesRule = { dtoField: 'type', dtoFieldValues: [ CaseNotificationType.COURT_DATE, - CaseNotificationType.COURT_OFFICIAL_ASSIGNED, + CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED, ], } 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 a281e586f06c..8e0f07bda84e 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 @@ -78,7 +78,8 @@ export class NotificationService { case CaseNotificationType.APPEAL_JUDGES_ASSIGNED: case CaseNotificationType.APPEAL_CASE_FILES_UPDATED: case CaseNotificationType.CASE_FILES_UPDATED: - case CaseNotificationType.COURT_OFFICIAL_ASSIGNED: + case CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED: + case CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED: messages = [this.getNotificationMessage(type, user, theCase)] break default: diff --git a/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts b/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts index bdb6be2808d9..505e7232a5ad 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts @@ -21,6 +21,7 @@ import { INDICTMENTS_OVERVIEW_ROUTE, INVESTIGATION_CASE_POLICE_CONFIRMATION_ROUTE, RESTRICTION_CASE_OVERVIEW_ROUTE, + ROUTE_HANDLER_ROUTE, SIGNED_VERDICT_OVERVIEW_ROUTE, } from '@island.is/judicial-system/consts' import { @@ -45,6 +46,7 @@ import { isRestrictionCase, RequestSharedWithDefender, SessionArrangements, + UserRole, type User, } from '@island.is/judicial-system/types' @@ -55,7 +57,6 @@ import { formatCourtReadyForCourtSmsNotification, formatCourtResubmittedToCourtSmsNotification, formatCourtRevokedSmsNotification, - formatCourtOfficialAssignedEmailNotification, formatDefenderCourtDateEmailNotification, formatDefenderCourtDateLinkEmailNotification, formatDefenderReadyForCourtEmailNotification, @@ -692,30 +693,20 @@ export class CaseNotificationService extends BaseNotificationService { private sendCourtOfficialAssignedEmailNotificationForIndictmentCase( theCase: Case, - overviewUrl?: string, - ): Promise[] { - const promises: Promise[] = [] - console.log('theCase.judge', theCase.judge?.email) - - for (const courtOfficial of [theCase.judge, theCase.registrar]) { - const { subject, body } = formatCourtOfficialAssignedEmailNotification( - this.formatMessage, - theCase.courtCaseNumber, - courtOfficial?.role, - overviewUrl, - ) - - promises.push( - this.sendEmail( - subject, - body, - courtOfficial?.name, - courtOfficial?.email, - ), - ) - } - - return promises + ): Promise { + return this.sendEmail( + this.formatMessage(notifications.courtOfficialAssignedEmail.subject, { + courtCaseNumber: theCase.courtCaseNumber, + }), + this.formatMessage(notifications.courtOfficialAssignedEmail.body, { + courtCaseNumber: theCase.courtCaseNumber, + role: UserRole.DISTRICT_COURT_JUDGE, + linkStart: ``, + linkEnd: '', + }), + theCase.judge?.name, + theCase.judge?.email, + ) } private sendCourtDateEmailNotificationForIndictmentCase( @@ -840,26 +831,18 @@ export class CaseNotificationService extends BaseNotificationService { return result } - private async sendCourtOfficialAssignedNotifications( + private async sendDistrictCourtJudgeAssignedNotifications( theCase: Case, - user: User, ): Promise { - const promises: Promise[] = [] - - if (isIndictmentCase(theCase.type)) { - promises.push( - ...this.sendCourtOfficialAssignedEmailNotificationForIndictmentCase( - theCase, - ), + const recipient = + await this.sendCourtOfficialAssignedEmailNotificationForIndictmentCase( + theCase, ) - } - - const recipients = await Promise.all(promises) const result = await this.recordNotification( theCase.id, - CaseNotificationType.COURT_OFFICIAL_ASSIGNED, - recipients, + CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED, + [recipient], ) return result @@ -2606,8 +2589,8 @@ export class CaseNotificationService extends BaseNotificationService { return this.sendReceivedByCourtNotifications(theCase) case CaseNotificationType.COURT_DATE: return this.sendCourtDateNotifications(theCase, user) - case CaseNotificationType.COURT_OFFICIAL_ASSIGNED: - return this.sendCourtOfficialAssignedNotifications(theCase, user) + case CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED: + return this.sendDistrictCourtJudgeAssignedNotifications(theCase) case CaseNotificationType.RULING: return this.sendRulingNotifications(theCase) case CaseNotificationType.MODIFIED: diff --git a/libs/judicial-system/types/src/lib/notification.ts b/libs/judicial-system/types/src/lib/notification.ts index f8823a0f77b3..abc67c1d2bd5 100644 --- a/libs/judicial-system/types/src/lib/notification.ts +++ b/libs/judicial-system/types/src/lib/notification.ts @@ -3,7 +3,8 @@ export enum CaseNotificationType { READY_FOR_COURT = 'READY_FOR_COURT', RECEIVED_BY_COURT = 'RECEIVED_BY_COURT', COURT_DATE = 'COURT_DATE', - COURT_OFFICIAL_ASSIGNED = 'COURT_OFFICIAL_ASSIGNED', + DISTRICT_COURT_JUDGE_ASSIGNED = 'DISTRICT_COURT_JUDGE_ASSIGNED', + DISTRICT_COURT_REGISTRAR_ASSIGNED = 'DISTRICT_COURT_REGISTRAR_ASSIGNED', RULING = 'RULING', MODIFIED = 'MODIFIED', REVOKED = 'REVOKED', @@ -46,7 +47,8 @@ export enum NotificationType { READY_FOR_COURT = CaseNotificationType.READY_FOR_COURT, RECEIVED_BY_COURT = CaseNotificationType.RECEIVED_BY_COURT, COURT_DATE = CaseNotificationType.COURT_DATE, - COURT_OFFICIAL_ASSIGNED = CaseNotificationType.COURT_OFFICIAL_ASSIGNED, + DISTRICT_COURT_JUDGE_ASSIGNED = CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED, + DISTRICT_COURT_REGISTRAR_ASSIGNED = CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED, RULING = CaseNotificationType.RULING, MODIFIED = CaseNotificationType.MODIFIED, REVOKED = CaseNotificationType.REVOKED, From 1ab4fed8d75d5b095857ce334c686a595156d2a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 6 Dec 2024 21:39:19 +0000 Subject: [PATCH 04/12] Send spesific registrar notifications --- .../src/app/modules/case/case.service.ts | 23 ++++++++++++- .../modules/notification/guards/rolesRules.ts | 2 ++ .../caseNotification.service.ts | 32 +++++++++++++++++-- 3 files changed, 53 insertions(+), 4 deletions(-) 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 17a8ed9d0e2d..844163b3b85c 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 @@ -700,6 +700,20 @@ export class CaseService { ]) } + private addMessagesForDistrictCourtRegistrarAssignedToQueue( + theCase: Case, + user: TUser, + ): Promise { + return this.messageService.sendMessagesToQueue([ + { + type: MessageType.NOTIFICATION, + user, + caseId: theCase.id, + body: { type: CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED }, + }, + ]) + } + private addMessagesForReceivedCaseToQueue( theCase: Case, user: TUser, @@ -1466,13 +1480,20 @@ export class CaseService { await this.addMessagesForNewCourtDateToQueue(updatedCase, user) } - if (judgeChanged || registrarChanged) { + if (judgeChanged) { await this.addMessagesForDistrictCourtJudgeAssignedToQueue( updatedCase, user, ) } + if (registrarChanged) { + await this.addMessagesForDistrictCourtRegistrarAssignedToQueue( + updatedCase, + user, + ) + } + await this.addMessagesForNewSubpoenasToQueue(theCase, updatedCase, user) } } 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 d21b142b0ea8..08971bd36031 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 @@ -36,6 +36,7 @@ export const districtCourtJudgeNotificationRule: RolesRule = { dtoFieldValues: [ CaseNotificationType.COURT_DATE, CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED, + CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED, ], } @@ -47,6 +48,7 @@ export const districtCourtRegistrarNotificationRule: RolesRule = { dtoFieldValues: [ CaseNotificationType.COURT_DATE, CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED, + CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED, ], } diff --git a/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts b/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts index 505e7232a5ad..e7c2743499dc 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts @@ -693,6 +693,7 @@ export class CaseNotificationService extends BaseNotificationService { private sendCourtOfficialAssignedEmailNotificationForIndictmentCase( theCase: Case, + role: UserRole.DISTRICT_COURT_JUDGE | UserRole.DISTRICT_COURT_REGISTRAR, ): Promise { return this.sendEmail( this.formatMessage(notifications.courtOfficialAssignedEmail.subject, { @@ -700,12 +701,16 @@ export class CaseNotificationService extends BaseNotificationService { }), this.formatMessage(notifications.courtOfficialAssignedEmail.body, { courtCaseNumber: theCase.courtCaseNumber, - role: UserRole.DISTRICT_COURT_JUDGE, + role, linkStart: ``, linkEnd: '', }), - theCase.judge?.name, - theCase.judge?.email, + role === UserRole.DISTRICT_COURT_JUDGE + ? theCase.judge?.name + : theCase.registrar?.name, + role === UserRole.DISTRICT_COURT_JUDGE + ? theCase.judge?.email + : theCase.registrar?.email, ) } @@ -837,6 +842,7 @@ export class CaseNotificationService extends BaseNotificationService { const recipient = await this.sendCourtOfficialAssignedEmailNotificationForIndictmentCase( theCase, + UserRole.DISTRICT_COURT_JUDGE, ) const result = await this.recordNotification( @@ -847,6 +853,24 @@ export class CaseNotificationService extends BaseNotificationService { return result } + + private async sendDistrictCourtRegistrarAssignedNotifications( + theCase: Case, + ): Promise { + const recipient = + await this.sendCourtOfficialAssignedEmailNotificationForIndictmentCase( + theCase, + UserRole.DISTRICT_COURT_REGISTRAR, + ) + + const result = await this.recordNotification( + theCase.id, + CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED, + [recipient], + ) + + return result + } //#endregion //#region RULING notifications @@ -2591,6 +2615,8 @@ export class CaseNotificationService extends BaseNotificationService { return this.sendCourtDateNotifications(theCase, user) case CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED: return this.sendDistrictCourtJudgeAssignedNotifications(theCase) + case CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED: + return this.sendDistrictCourtRegistrarAssignedNotifications(theCase) case CaseNotificationType.RULING: return this.sendRulingNotifications(theCase) case CaseNotificationType.MODIFIED: From b6bec23eb3aa4bdc3d4c3d536d178028df86edd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 6 Dec 2024 21:49:18 +0000 Subject: [PATCH 05/12] Send notifications in states received and submitted --- .../src/app/modules/case/case.service.ts | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) 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 844163b3b85c..8772e87adad4 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 @@ -1414,6 +1414,30 @@ export class CaseService { } } + if ( + isIndictment && + [CaseState.SUBMITTED, CaseState.RECEIVED].includes(updatedCase.state) + ) { + const judgeChanged = + updatedCase.judge?.nationalId !== theCase.judge?.nationalId + const registrarChanged = + updatedCase.registrar?.nationalId !== theCase.registrar?.nationalId + + if (judgeChanged) { + await this.addMessagesForDistrictCourtJudgeAssignedToQueue( + updatedCase, + user, + ) + } + + if (registrarChanged) { + await this.addMessagesForDistrictCourtRegistrarAssignedToQueue( + updatedCase, + user, + ) + } + } + if ( isIndictment && ![ @@ -1470,30 +1494,12 @@ export class CaseService { const courtDateChanged = updatedCourtDate && updatedCourtDate.date.getTime() !== courtDate?.date.getTime() - const judgeChanged = - updatedCase.judge?.nationalId !== theCase.judge?.nationalId - const registrarChanged = - updatedCase.registrar?.nationalId !== theCase.registrar?.nationalId if (arraignmentDateChanged || courtDateChanged) { // New arraignment date or new court date await this.addMessagesForNewCourtDateToQueue(updatedCase, user) } - if (judgeChanged) { - await this.addMessagesForDistrictCourtJudgeAssignedToQueue( - updatedCase, - user, - ) - } - - if (registrarChanged) { - await this.addMessagesForDistrictCourtRegistrarAssignedToQueue( - updatedCase, - user, - ) - } - await this.addMessagesForNewSubpoenasToQueue(theCase, updatedCase, user) } } From e094958dab3f7ce13c12e36a9b35552cf74b6353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 6 Dec 2024 21:49:59 +0000 Subject: [PATCH 06/12] Cleanup --- apps/judicial-system/backend/src/app/formatters/formatters.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/judicial-system/backend/src/app/formatters/formatters.ts b/apps/judicial-system/backend/src/app/formatters/formatters.ts index 1bbc13c9446a..0f43edf7200b 100644 --- a/apps/judicial-system/backend/src/app/formatters/formatters.ts +++ b/apps/judicial-system/backend/src/app/formatters/formatters.ts @@ -1,4 +1,4 @@ -import type { formatMessage, FormatMessage } from '@island.is/cms-translations' +import type { FormatMessage } from '@island.is/cms-translations' import { DEFENDER_INDICTMENT_ROUTE, From 82972b40dd3bad3841af1643ec46880d512a24df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 13 Dec 2024 15:05:08 +0000 Subject: [PATCH 07/12] Merge --- libs/judicial-system/types/src/lib/notification.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/libs/judicial-system/types/src/lib/notification.ts b/libs/judicial-system/types/src/lib/notification.ts index fe7fcd26a692..ee863976b056 100644 --- a/libs/judicial-system/types/src/lib/notification.ts +++ b/libs/judicial-system/types/src/lib/notification.ts @@ -51,18 +51,6 @@ export enum EventNotificationType { } export enum NotificationType { -<<<<<<< HEAD -======= - HEADS_UP = CaseNotificationType.HEADS_UP, - READY_FOR_COURT = CaseNotificationType.READY_FOR_COURT, - RECEIVED_BY_COURT = CaseNotificationType.RECEIVED_BY_COURT, - COURT_DATE = CaseNotificationType.COURT_DATE, - DISTRICT_COURT_JUDGE_ASSIGNED = CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED, - DISTRICT_COURT_REGISTRAR_ASSIGNED = CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED, - RULING = CaseNotificationType.RULING, - MODIFIED = CaseNotificationType.MODIFIED, - REVOKED = CaseNotificationType.REVOKED, ->>>>>>> c1f1fe4e35cb050939a9f44c6abb649bca58472a ADVOCATE_ASSIGNED = CaseNotificationType.ADVOCATE_ASSIGNED, APPEAL_CASE_FILES_UPDATED = CaseNotificationType.APPEAL_CASE_FILES_UPDATED, APPEAL_COMPLETED = CaseNotificationType.APPEAL_COMPLETED, From 54c8da51eeb54522fe7cd0665558652f23f8834b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 13 Dec 2024 15:07:31 +0000 Subject: [PATCH 08/12] Remove console.log --- .../backend/src/app/modules/case/case.service.ts | 2 -- 1 file changed, 2 deletions(-) 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 8772e87adad4..57ec6a0c64fa 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 @@ -1305,8 +1305,6 @@ export class CaseService { ): Promise { const isIndictment = isIndictmentCase(updatedCase.type) - console.log('!!!!!!!!!!!!!!!!!!!!!!', { isIndictment: updatedCase.state }) - if (updatedCase.state !== theCase.state) { // New case state if ( From 82bf235ac9b2c22c0eb496aa699b85286b9e5814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 13 Dec 2024 15:19:29 +0000 Subject: [PATCH 09/12] Refactor --- .../caseNotification/caseNotification.service.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts b/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts index e7c2743499dc..fb94e1a2eb70 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts @@ -46,8 +46,8 @@ import { isRestrictionCase, RequestSharedWithDefender, SessionArrangements, - UserRole, type User, + UserRole, } from '@island.is/judicial-system/types' import { @@ -695,6 +695,9 @@ export class CaseNotificationService extends BaseNotificationService { theCase: Case, role: UserRole.DISTRICT_COURT_JUDGE | UserRole.DISTRICT_COURT_REGISTRAR, ): Promise { + const official = + role === UserRole.DISTRICT_COURT_JUDGE ? theCase.judge : theCase.registrar + return this.sendEmail( this.formatMessage(notifications.courtOfficialAssignedEmail.subject, { courtCaseNumber: theCase.courtCaseNumber, @@ -705,12 +708,8 @@ export class CaseNotificationService extends BaseNotificationService { linkStart: ``, linkEnd: '', }), - role === UserRole.DISTRICT_COURT_JUDGE - ? theCase.judge?.name - : theCase.registrar?.name, - role === UserRole.DISTRICT_COURT_JUDGE - ? theCase.judge?.email - : theCase.registrar?.email, + official?.name, + official?.email, ) } From 59bd7a55d01a62524210a90792640bc79c4f16fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 13 Dec 2024 15:25:08 +0000 Subject: [PATCH 10/12] Refactor --- .../caseNotification.service.ts | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts b/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts index fb94e1a2eb70..fe2aa576b272 100644 --- a/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts +++ b/apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts @@ -835,40 +835,23 @@ export class CaseNotificationService extends BaseNotificationService { return result } - private async sendDistrictCourtJudgeAssignedNotifications( + private async sendDistrictCourtUserAssignedNotifications( theCase: Case, + userRole: UserRole.DISTRICT_COURT_JUDGE | UserRole.DISTRICT_COURT_REGISTRAR, ): Promise { const recipient = await this.sendCourtOfficialAssignedEmailNotificationForIndictmentCase( theCase, - UserRole.DISTRICT_COURT_JUDGE, + userRole, ) - const result = await this.recordNotification( - theCase.id, - CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED, - [recipient], - ) - - return result - } - - private async sendDistrictCourtRegistrarAssignedNotifications( - theCase: Case, - ): Promise { - const recipient = - await this.sendCourtOfficialAssignedEmailNotificationForIndictmentCase( - theCase, - UserRole.DISTRICT_COURT_REGISTRAR, - ) - - const result = await this.recordNotification( + return await this.recordNotification( theCase.id, - CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED, + userRole === UserRole.DISTRICT_COURT_JUDGE + ? CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED + : CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED, [recipient], ) - - return result } //#endregion @@ -2613,9 +2596,15 @@ export class CaseNotificationService extends BaseNotificationService { case CaseNotificationType.COURT_DATE: return this.sendCourtDateNotifications(theCase, user) case CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED: - return this.sendDistrictCourtJudgeAssignedNotifications(theCase) + return this.sendDistrictCourtUserAssignedNotifications( + theCase, + UserRole.DISTRICT_COURT_JUDGE, + ) case CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED: - return this.sendDistrictCourtRegistrarAssignedNotifications(theCase) + return this.sendDistrictCourtUserAssignedNotifications( + theCase, + UserRole.DISTRICT_COURT_REGISTRAR, + ) case CaseNotificationType.RULING: return this.sendRulingNotifications(theCase) case CaseNotificationType.MODIFIED: From 77fe61b0aa2fdea3b22a78efe362567c4a89c7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 13 Dec 2024 21:42:00 +0000 Subject: [PATCH 11/12] Rename variables --- .../backend/src/app/modules/case/case.service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 8772e87adad4..c0fa3951342d 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 @@ -1418,19 +1418,19 @@ export class CaseService { isIndictment && [CaseState.SUBMITTED, CaseState.RECEIVED].includes(updatedCase.state) ) { - const judgeChanged = + const isJudgeChanged = updatedCase.judge?.nationalId !== theCase.judge?.nationalId - const registrarChanged = + const isRegistrarChanged = updatedCase.registrar?.nationalId !== theCase.registrar?.nationalId - if (judgeChanged) { + if (isJudgeChanged) { await this.addMessagesForDistrictCourtJudgeAssignedToQueue( updatedCase, user, ) } - if (registrarChanged) { + if (isRegistrarChanged) { await this.addMessagesForDistrictCourtRegistrarAssignedToQueue( updatedCase, user, From 270f8ea127da7a09c2c01846f22c0167d9990425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 13 Dec 2024 21:45:40 +0000 Subject: [PATCH 12/12] Remove redundant code --- .../app/modules/notification/guards/rolesRules.ts | 12 ++---------- .../app/modules/notification/notification.service.ts | 2 -- 2 files changed, 2 insertions(+), 12 deletions(-) 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 08971bd36031..567e17620945 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 @@ -33,11 +33,7 @@ export const districtCourtJudgeNotificationRule: RolesRule = { role: UserRole.DISTRICT_COURT_JUDGE, type: RulesType.FIELD_VALUES, dtoField: 'type', - dtoFieldValues: [ - CaseNotificationType.COURT_DATE, - CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED, - CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED, - ], + dtoFieldValues: [CaseNotificationType.COURT_DATE], } // Allows district court registrars to send notifications @@ -45,11 +41,7 @@ export const districtCourtRegistrarNotificationRule: RolesRule = { role: UserRole.DISTRICT_COURT_REGISTRAR, type: RulesType.FIELD_VALUES, dtoField: 'type', - dtoFieldValues: [ - CaseNotificationType.COURT_DATE, - CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED, - CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED, - ], + dtoFieldValues: [CaseNotificationType.COURT_DATE], } // Allows district court assistants to send notifications 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 8e0f07bda84e..7801234f9ae6 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 @@ -78,8 +78,6 @@ export class NotificationService { case CaseNotificationType.APPEAL_JUDGES_ASSIGNED: case CaseNotificationType.APPEAL_CASE_FILES_UPDATED: case CaseNotificationType.CASE_FILES_UPDATED: - case CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED: - case CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED: messages = [this.getNotificationMessage(type, user, theCase)] break default: