Skip to content

Commit

Permalink
chore(j-s): Slack event when subpoena is serviced (#16747)
Browse files Browse the repository at this point in the history
* chore(j-s): Post event to slack when subpoena status updates

* chore(j-s): Slack event when service status changes

* chore: nx format:write update dirty files

* fix(j-s): Mock event service

* Update createTestingSubpoenaModule.ts

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 8, 2024
1 parent e552b2d commit 4cc1e8b
Showing 6 changed files with 60 additions and 15 deletions.
39 changes: 28 additions & 11 deletions apps/judicial-system/backend/src/app/modules/event/event.service.ts
Original file line number Diff line number Diff line change
@@ -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ð',
@@ -75,6 +76,7 @@ export type CaseEvent =
| 'EXTEND'
| 'RESUBMIT'
| 'SCHEDULE_COURT_DATE'
| 'SUBPOENA_SERVICE_STATUS'

@Injectable()
export class EventService {
@@ -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
@@ -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'
@@ -128,6 +135,8 @@ export class EventService {
}`
: ''

const infoText = this.getInfoText(info)

await fetch(`${this.config.url}`, {
method: 'POST',
headers: { 'Content-type': 'application/json' },
@@ -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}`,
},
},
],
@@ -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',
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -32,10 +32,7 @@ import {
} from '../case'
import { CurrentDefendant, Defendant, DefendantExistsGuard } from '../defendant'
import { CurrentSubpoena } from './guards/subpoena.decorator'
import {
SubpoenaExistsGuard,
SubpoenaExistsOptionalGuard,
} from './guards/subpoenaExists.guard'
import { SubpoenaExistsOptionalGuard } from './guards/subpoenaExists.guard'
import { Subpoena } from './models/subpoena.model'

@Controller([
Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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'
@@ -19,6 +20,8 @@ import { SubpoenaService } from './subpoena.service'
forwardRef(() => PoliceModule),
forwardRef(() => FileModule),
forwardRef(() => MessageModule),
forwardRef(() => EventModule),

SequelizeModule.forFeature([Subpoena, Defendant]),
],
controllers: [
Original file line number Diff line number Diff line change
@@ -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'
@@ -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,
) {}

@@ -239,6 +241,15 @@ export class SubpoenaService {
defenderNationalId,
)

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

return this.findBySubpoenaId(subpoena.subpoenaId)
}

Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ import { MessageService } from '@island.is/judicial-system/message'

import { CaseService, PdfService } from '../../case'
import { Defendant } from '../../defendant'
import { EventService } from '../../event'
import { FileService } from '../../file'
import { PoliceService } from '../../police'
import { UserService } from '../../user'
@@ -28,6 +29,7 @@ jest.mock('../../case/case.service')
jest.mock('../../case/pdf.service')
jest.mock('../../police/police.service')
jest.mock('../../file/file.service')
jest.mock('../../event/event.service')
jest.mock('@island.is/judicial-system/message')

export const createTestingSubpoenaModule = async () => {
@@ -46,6 +48,7 @@ export const createTestingSubpoenaModule = async () => {
PdfService,
PoliceService,
FileService,
EventService,
{
provide: LOGGER_PROVIDER,
useValue: {

0 comments on commit 4cc1e8b

Please sign in to comment.