diff --git a/apps/judicial-system/backend/src/app/modules/event/event.service.ts b/apps/judicial-system/backend/src/app/modules/event/event.service.ts index 56c762f6299a..36b84bf40361 100644 --- a/apps/judicial-system/backend/src/app/modules/event/event.service.ts +++ b/apps/judicial-system/backend/src/app/modules/event/event.service.ts @@ -62,6 +62,7 @@ const caseEvent: Record = { 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 + } } diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/limitedAccessSubpoena.controller.ts b/apps/judicial-system/backend/src/app/modules/subpoena/limitedAccessSubpoena.controller.ts index 4e96f92e24d0..36e2676df68b 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/limitedAccessSubpoena.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/limitedAccessSubpoena.controller.ts @@ -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([ diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts b/apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts index 513d5daa5a2d..4f106b1f8894 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts @@ -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, diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts index 42f6249d39f2..57b9d55af2be 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts @@ -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: [ diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts index 5e67723790ec..62e0eae1fc01 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts @@ -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) } diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts index b25adab82dfa..4a7f93290f45 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts @@ -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: {