Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(j-s): Notifications sent when court officials are assigned #17169

Merged
merged 19 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -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}',
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
description:
'Texti í pósti til dómara og dómritara þegar máli er úthlutað á þau',
},
}),
}
Original file line number Diff line number Diff line change
@@ -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,
@@ -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 &&
![
Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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 {
@@ -46,6 +47,7 @@ import {
RequestSharedWithDefender,
SessionArrangements,
type User,
UserRole,
} from '@island.is/judicial-system/types'

import {
@@ -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,
@@ -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
@@ -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:
2 changes: 2 additions & 0 deletions libs/judicial-system/types/src/lib/notification.ts
Original file line number Diff line number Diff line change
@@ -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',