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
Show file tree
Hide file tree
Changes from 8 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
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}',
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
Expand Up @@ -686,6 +686,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 @@ -1277,6 +1305,8 @@ export class CaseService {
): Promise<void> {
const isIndictment = isIndictmentCase(updatedCase.type)

console.log('!!!!!!!!!!!!!!!!!!!!!!', { isIndictment: updatedCase.state })
oddsson marked this conversation as resolved.
Show resolved Hide resolved

if (updatedCase.state !== theCase.state) {
// New case state
if (
Expand Down Expand Up @@ -1384,6 +1414,30 @@ export class CaseService {
}
}

if (
isIndictment &&
[CaseState.SUBMITTED, CaseState.RECEIVED].includes(updatedCase.state)
) {
const judgeChanged =
oddsson marked this conversation as resolved.
Show resolved Hide resolved
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 &&
![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,28 @@ 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.DISTRICT_COURT_JUDGE_ASSIGNED,
CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED,
],
oddsson marked this conversation as resolved.
Show resolved Hide resolved
}

// Allows district court registrars to send notifications
export const districtCourtRegistrarNotificationRule: RolesRule = {
role: UserRole.DISTRICT_COURT_REGISTRAR,
type: RulesType.FIELD_VALUES,
dtoField: 'type',
dtoFieldValues: [CaseNotificationType.COURT_DATE],
dtoFieldValues: [
CaseNotificationType.COURT_DATE,
CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED,
CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED,
],
oddsson marked this conversation as resolved.
Show resolved Hide resolved
}

// Allows district court assistants to send notifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ 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:
oddsson marked this conversation as resolved.
Show resolved Hide resolved
messages = [this.getNotificationMessage(type, user, theCase)]
break
default:
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 @@ -45,6 +46,7 @@ import {
isRestrictionCase,
RequestSharedWithDefender,
SessionArrangements,
UserRole,
type User,
} from '@island.is/judicial-system/types'

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

private sendCourtOfficialAssignedEmailNotificationForIndictmentCase(
theCase: Case,
role: UserRole.DISTRICT_COURT_JUDGE | UserRole.DISTRICT_COURT_REGISTRAR,
): Promise<Recipient> {
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>',
}),
role === UserRole.DISTRICT_COURT_JUDGE
? theCase.judge?.name
: theCase.registrar?.name,
role === UserRole.DISTRICT_COURT_JUDGE
oddsson marked this conversation as resolved.
Show resolved Hide resolved
? theCase.judge?.email
: theCase.registrar?.email,
)
}

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

return result
}

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

const result = await this.recordNotification(
theCase.id,
CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED,
[recipient],
)

return result
}

private async sendDistrictCourtRegistrarAssignedNotifications(
oddsson marked this conversation as resolved.
Show resolved Hide resolved
theCase: Case,
): Promise<DeliverResponse> {
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
Expand Down Expand Up @@ -2552,6 +2613,10 @@ 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.sendDistrictCourtJudgeAssignedNotifications(theCase)
case CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED:
return this.sendDistrictCourtRegistrarAssignedNotifications(theCase)
case CaseNotificationType.RULING:
return this.sendRulingNotifications(theCase)
case CaseNotificationType.MODIFIED:
Expand Down
4 changes: 4 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 Expand Up @@ -45,6 +47,8 @@ export enum NotificationType {
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,
Expand Down
Loading