Skip to content

Commit

Permalink
feat(j-s): Notifications sent when court officials are assigned (#17169)
Browse files Browse the repository at this point in the history
* Send notifications to court officials

* Fix body

* Send spesific judge notification

* Send spesific registrar notifications

* Send notifications in states received and submitted

* Cleanup

* Merge

* Remove console.log

* Refactor

* Refactor

* Rename variables

* Remove redundant code

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
oddsson and kodiakhq[bot] authored Dec 16, 2024
1 parent 4fcc879 commit cfe3d07
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 1 deletion.
15 changes: 15 additions & 0 deletions apps/judicial-system/backend/src/app/messages/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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',
},
}),
}
52 changes: 52 additions & 0 deletions apps/judicial-system/backend/src/app/modules/case/case.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,34 @@ export class CaseService {
])
}

private addMessagesForDistrictCourtJudgeAssignedToQueue(
theCase: Case,
user: TUser,
): Promise<void> {
return this.messageService.sendMessagesToQueue([
{
type: MessageType.NOTIFICATION,
user,
caseId: theCase.id,
body: { type: CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED },
},
])
}

private addMessagesForDistrictCourtRegistrarAssignedToQueue(
theCase: Case,
user: TUser,
): Promise<void> {
return this.messageService.sendMessagesToQueue([
{
type: MessageType.NOTIFICATION,
user,
caseId: theCase.id,
body: { type: CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED },
},
])
}

private addMessagesForReceivedCaseToQueue(
theCase: Case,
user: TUser,
Expand Down Expand Up @@ -1403,6 +1431,30 @@ export class CaseService {
}
}

if (
isIndictment &&
[CaseState.SUBMITTED, CaseState.RECEIVED].includes(updatedCase.state)
) {
const isJudgeChanged =
updatedCase.judge?.nationalId !== theCase.judge?.nationalId
const isRegistrarChanged =
updatedCase.registrar?.nationalId !== theCase.registrar?.nationalId

if (isJudgeChanged) {
await this.addMessagesForDistrictCourtJudgeAssignedToQueue(
updatedCase,
user,
)
}

if (isRegistrarChanged) {
await this.addMessagesForDistrictCourtRegistrarAssignedToQueue(
updatedCase,
user,
)
}
}

if (
isIndictment &&
![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -46,6 +47,7 @@ import {
RequestSharedWithDefender,
SessionArrangements,
type User,
UserRole,
} from '@island.is/judicial-system/types'

import {
Expand Down Expand Up @@ -689,6 +691,28 @@ export class CaseNotificationService extends BaseNotificationService {
})
}

private sendCourtOfficialAssignedEmailNotificationForIndictmentCase(
theCase: Case,
role: UserRole.DISTRICT_COURT_JUDGE | UserRole.DISTRICT_COURT_REGISTRAR,
): Promise<Recipient> {
const official =
role === UserRole.DISTRICT_COURT_JUDGE ? theCase.judge : theCase.registrar

return this.sendEmail(
this.formatMessage(notifications.courtOfficialAssignedEmail.subject, {
courtCaseNumber: theCase.courtCaseNumber,
}),
this.formatMessage(notifications.courtOfficialAssignedEmail.body, {
courtCaseNumber: theCase.courtCaseNumber,
role,
linkStart: `<a href="${this.config.clientUrl}${ROUTE_HANDLER_ROUTE}/${theCase.id}">`,
linkEnd: '</a>',
}),
official?.name,
official?.email,
)
}

private sendCourtDateEmailNotificationForIndictmentCase(
theCase: Case,
user: User,
Expand Down Expand Up @@ -810,6 +834,25 @@ export class CaseNotificationService extends BaseNotificationService {

return result
}

private async sendDistrictCourtUserAssignedNotifications(
theCase: Case,
userRole: UserRole.DISTRICT_COURT_JUDGE | UserRole.DISTRICT_COURT_REGISTRAR,
): Promise<DeliverResponse> {
const recipient =
await this.sendCourtOfficialAssignedEmailNotificationForIndictmentCase(
theCase,
userRole,
)

return await this.recordNotification(
theCase.id,
userRole === UserRole.DISTRICT_COURT_JUDGE
? CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED
: CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED,
[recipient],
)
}
//#endregion

//#region RULING notifications
Expand Down Expand Up @@ -2552,6 +2595,16 @@ export class CaseNotificationService extends BaseNotificationService {
return this.sendReceivedByCourtNotifications(theCase)
case CaseNotificationType.COURT_DATE:
return this.sendCourtDateNotifications(theCase, user)
case CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED:
return this.sendDistrictCourtUserAssignedNotifications(
theCase,
UserRole.DISTRICT_COURT_JUDGE,
)
case CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED:
return this.sendDistrictCourtUserAssignedNotifications(
theCase,
UserRole.DISTRICT_COURT_REGISTRAR,
)
case CaseNotificationType.RULING:
return this.sendRulingNotifications(theCase)
case CaseNotificationType.MODIFIED:
Expand Down
2 changes: 2 additions & 0 deletions libs/judicial-system/types/src/lib/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export enum CaseNotificationType {
READY_FOR_COURT = 'READY_FOR_COURT',
RECEIVED_BY_COURT = 'RECEIVED_BY_COURT',
COURT_DATE = 'COURT_DATE',
DISTRICT_COURT_JUDGE_ASSIGNED = 'DISTRICT_COURT_JUDGE_ASSIGNED',
DISTRICT_COURT_REGISTRAR_ASSIGNED = 'DISTRICT_COURT_REGISTRAR_ASSIGNED',
RULING = 'RULING',
MODIFIED = 'MODIFIED',
REVOKED = 'REVOKED',
Expand Down

0 comments on commit cfe3d07

Please sign in to comment.