Skip to content

Commit

Permalink
chore(j-s): Slack event when service status changes
Browse files Browse the repository at this point in the history
  • Loading branch information
unakb committed Nov 6, 2024
1 parent 37ed095 commit 3898da2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
32 changes: 21 additions & 11 deletions apps/judicial-system/backend/src/app/modules/event/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class EventService {
event: CaseEvent,
theCase: Case,
eventOnly = false,
extraInfo = '',
info?: { [key: string]: string | boolean | Date | undefined },
) {
try {
if (!this.config.url) {
Expand Down Expand Up @@ -120,7 +120,7 @@ export class EventService {
const courtOfAppealsText = theCase.appealCaseNumber
? `\n>Landsréttur *${theCase.appealCaseNumber}*`
: ''
const extraText =
const courtDateText =
event === 'SCHEDULE_COURT_DATE'
? `\n>Dómari ${
theCase.judge?.name ?? 'er ekki skráður'
Expand All @@ -135,6 +135,8 @@ export class EventService {
}`
: ''

const infoText = this.getInfoText(info)

await fetch(`${this.config.url}`, {
method: 'POST',
headers: { 'Content-type': 'application/json' },
Expand All @@ -144,7 +146,7 @@ export class EventService {
type: 'section',
text: {
type: 'mrkdwn',
text: `*${title}*\n>${typeText}\n>${prosecutionText}${courtText}${courtOfAppealsText}${extraText}\n>${extraInfo}`,
text: `*${title}*\n>${typeText}\n>${prosecutionText}${courtText}${courtOfAppealsText}${courtDateText}\n>${infoText}`,
},
},
],
Expand All @@ -169,14 +171,7 @@ export class EventService {
return
}

let infoText = ''

if (info) {
let property: keyof typeof info
for (property in info) {
infoText = `${infoText}${property}: ${info[property]}\n`
}
}
const infoText = this.getInfoText(info)

await fetch(`${this.config.errorUrl}`, {
method: 'POST',
Expand All @@ -200,4 +195,19 @@ export class EventService {
this.logger.error(`Failed to post an error event`, { error })
}
}

getInfoText = (info?: {
[key: string]: string | boolean | Date | undefined
}) => {
let infoText = ''

if (info) {
let property: keyof typeof info
for (property in info) {
infoText = `${infoText}${property}: ${info[property]}\n`
}
}

return infoText
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ import { Defendant } from '../../defendant/models/defendant.model'
timestamps: true,
})
export class Subpoena extends Model {
static serviceStatusText(serviceStatus: ServiceStatus) {
return serviceStatus === ServiceStatus.DEFENDER
? 'Birt fyrir verjanda'
: serviceStatus === ServiceStatus.ELECTRONICALLY
? 'Birt rafrænt'
: serviceStatus === ServiceStatus.IN_PERSON
? 'Birt persónulega'
: serviceStatus === ServiceStatus.FAILED
? 'Árangurslaus birting'
: serviceStatus === ServiceStatus.EXPIRED
? 'Rann út á tíma'
: 'Í birtingarferli' // This should never happen
}

@Column({
type: DataType.UUID,
primaryKey: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,25 +241,16 @@ export class SubpoenaService {
defenderNationalId,
)

if (update.serviceStatus && !subpoena.serviceStatus && subpoena.case) {
const serviceStatus =
update.serviceStatus === ServiceStatus.DEFENDER
? 'Birt fyrir verjanda'
: update.serviceStatus === ServiceStatus.ELECTRONICALLY
? 'Birt rafrænt'
: update.serviceStatus === ServiceStatus.IN_PERSON
? 'Birt persónulega'
: update.serviceStatus === ServiceStatus.FAILED
? 'Árangurslaus birting'
: update.serviceStatus === ServiceStatus.EXPIRED
? 'Rann út á tíma'
: 'Í birtingarferli' // This should never happen
if (
update.serviceStatus &&

subpoena.case
) {
this.eventService.postEvent(
'SUBPOENA_SERVICE_STATUS',
subpoena.case,
false,
serviceStatus,
{ Staða: Subpoena.serviceStatusText(update.serviceStatus) },
)
}

Expand Down

0 comments on commit 3898da2

Please sign in to comment.