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

chore(j-s): Slack event when subpoena is serviced #16747

Merged
merged 8 commits into from
Nov 8, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const caseEvent: Record<CaseEvent, string> = {
RESUBMIT: ':mailbox_with_mail: Sent aftur',
[CaseTransition.RETURN_INDICTMENT]: ':woman-gesturing-no: Ákæru afturkallað',
SCHEDULE_COURT_DATE: ':timer_clock: Fyrirtökutíma úthlutað',
SUBPOENA_SERVICE_STATUS: ':page_with_curl: Staða fyrirkalls uppfærð',
[CaseTransition.SUBMIT]: ':mailbox_with_mail: Sent',
[CaseTransition.WITHDRAW_APPEAL]:
':leftwards_arrow_with_hook: Kæru afturkallað',
Expand All @@ -75,6 +76,7 @@ export type CaseEvent =
| 'EXTEND'
| 'RESUBMIT'
| 'SCHEDULE_COURT_DATE'
| 'SUBPOENA_SERVICE_STATUS'

@Injectable()
export class EventService {
Expand All @@ -85,7 +87,12 @@ export class EventService {
private readonly logger: Logger,
) {}

async postEvent(event: CaseEvent, theCase: Case, eventOnly = false) {
async postEvent(
event: CaseEvent,
theCase: Case,
eventOnly = false,
info?: { [key: string]: string | boolean | Date | undefined },
) {
try {
if (!this.config.url) {
return
Expand Down Expand Up @@ -113,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 @@ -128,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 @@ -137,7 +146,7 @@ export class EventService {
type: 'section',
text: {
type: 'mrkdwn',
text: `*${title}*\n>${typeText}\n>${prosecutionText}${courtText}${courtOfAppealsText}${extraText}`,
text: `*${title}*\n>${typeText}\n>${prosecutionText}${courtText}${courtOfAppealsText}${courtDateText}\n>${infoText}`,
},
},
],
Expand All @@ -162,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 @@ -193,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
}
unakb marked this conversation as resolved.
Show resolved Hide resolved
}
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
oddsson marked this conversation as resolved.
Show resolved Hide resolved
}

@Column({
type: DataType.UUID,
primaryKey: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MessageModule } from '@island.is/judicial-system/message'

import { CaseModule } from '../case/case.module'
import { Defendant } from '../defendant/models/defendant.model'
import { EventModule } from '../event/event.module'
import { FileModule } from '../file/file.module'
import { PoliceModule } from '../police/police.module'
import { Subpoena } from './models/subpoena.model'
Expand All @@ -19,6 +20,8 @@ import { SubpoenaService } from './subpoena.service'
forwardRef(() => PoliceModule),
forwardRef(() => FileModule),
forwardRef(() => MessageModule),
forwardRef(() => EventModule),

SequelizeModule.forFeature([Subpoena, Defendant]),
],
controllers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import { Case } from '../case/models/case.model'
import { PdfService } from '../case/pdf.service'
import { Defendant } from '../defendant/models/defendant.model'
import { EventService } from '../event'
import { FileService } from '../file'
import { PoliceService } from '../police'
import { User } from '../user'
Expand Down Expand Up @@ -69,6 +70,7 @@ export class SubpoenaService {
private readonly policeService: PoliceService,
@Inject(forwardRef(() => FileService))
private readonly fileService: FileService,
private readonly eventService: EventService,
@Inject(LOGGER_PROVIDER) private readonly logger: Logger,
) {}

Expand Down Expand Up @@ -239,6 +241,19 @@ export class SubpoenaService {
defenderNationalId,
)

if (
update.serviceStatus &&

subpoena.case
) {
this.eventService.postEvent(
'SUBPOENA_SERVICE_STATUS',
subpoena.case,
false,
{ Staða: Subpoena.serviceStatusText(update.serviceStatus) },
)
}
unakb marked this conversation as resolved.
Show resolved Hide resolved

return this.findBySubpoenaId(subpoena.subpoenaId)
}

Expand Down
Loading