Skip to content

Commit

Permalink
fix(j-s): Undefined Slack Events (#15831)
Browse files Browse the repository at this point in the history
* Fixes undefined event post

* Adds type definition to event map

---------

Co-authored-by: unakb <una@kolibri.is>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 3, 2024
1 parent 5786cb9 commit 4f1a362
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class CaseController {

const createdCase = await this.caseService.create(caseToCreate, user)

this.eventService.postEvent(CaseEvent.CREATE, createdCase as Case)
this.eventService.postEvent('CREATE', createdCase)

return createdCase
}
Expand Down Expand Up @@ -419,10 +419,7 @@ export class CaseController {
)

// No need to wait
this.eventService.postEvent(
transition.transition as unknown as CaseEvent,
updatedCase ?? theCase,
)
this.eventService.postEvent(transition.transition, updatedCase ?? theCase)

return updatedCase ?? theCase
}
Expand Down Expand Up @@ -891,7 +888,7 @@ export class CaseController {

const extendedCase = await this.caseService.extend(theCase, user)

this.eventService.postEvent(CaseEvent.EXTEND, extendedCase as Case)
this.eventService.postEvent('EXTEND', extendedCase as Case)

return extendedCase
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ export class CaseService {
await this.addMessagesForUpdatedCaseToQueue(theCase, updatedCase, user)

if (receivingCase) {
this.eventService.postEvent(CaseEvent.RECEIVE, updatedCase)
this.eventService.postEvent(CaseTransition.RECEIVE, updatedCase)
}

if (returnUpdatedCase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class InternalCaseController {

const createdCase = await this.internalCaseService.create(caseToCreate)

this.eventService.postEvent(CaseEvent.CREATE_XRD, createdCase as Case)
this.eventService.postEvent('CREATE_XRD', createdCase as Case)

return createdCase
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export class InternalCaseService {
)
})

this.eventService.postEvent(CaseEvent.ARCHIVE, theCase)
this.eventService.postEvent('ARCHIVE', theCase)

return { caseArchived: true }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ export class LimitedAccessCaseController {
user,
)

this.eventService.postEvent(
transition.transition as unknown as CaseEvent,
updatedCase,
)
this.eventService.postEvent(transition.transition, updatedCase)

return updatedCase
}
Expand Down
73 changes: 34 additions & 39 deletions apps/judicial-system/backend/src/app/modules/event/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
formatDate,
readableIndictmentSubtypes,
} from '@island.is/judicial-system/formatters'
import { isIndictmentCase } from '@island.is/judicial-system/types'
import {
CaseTransition,
isIndictmentCase,
} from '@island.is/judicial-system/types'

import { type Case } from '../case'
import { DateLog } from '../case/models/dateLog.model'
Expand All @@ -37,50 +40,42 @@ const errorEmojis = [
':x:',
]

const caseEvent = {
const caseEvent: Record<CaseEvent, string> = {
[CaseTransition.ACCEPT]: ':white_check_mark: Samþykkt',
[CaseTransition.APPEAL]: ':judge: Kæra',
ARCHIVE: ':file_cabinet: Sett í geymslu',
[CaseTransition.ASK_FOR_CANCELLATION]: ':interrobang: Beðið um aftuköllun',
[CaseTransition.ASK_FOR_CONFIRMATION]: ':question: Beðið um staðfestingu',
[CaseTransition.COMPLETE]: ':white_check_mark: Lokið',
[CaseTransition.COMPLETE_APPEAL]: ':white_check_mark: Kæru lokið',
[CaseTransition.DELETE]: ':fire: Afturkallað',
[CaseTransition.DENY_INDICTMENT]: ':no_entry_sign: Ákæru hafnað',
[CaseTransition.DISMISS]: ':woman-shrugging: Vísað frá',
CREATE: ':new: Mál stofnað',
CREATE_XRD: ':new: Mál stofnað í gegnum Strauminn',
EXTEND: ':recycle: Mál framlengt',
OPEN: ':unlock: Opnað fyrir dómstól',
ASK_FOR_CONFIRMATION: ':question: Beðið um staðfestingu',
SUBMIT: ':mailbox_with_mail: Sent',
[CaseTransition.OPEN]: ':unlock: Opnað fyrir dómstól',
[CaseTransition.RECEIVE]: ':eyes: Móttekið',
[CaseTransition.RECEIVE_APPEAL]: ':eyes: Kæra móttekin',
[CaseTransition.REJECT]: ':negative_squared_cross_mark: Hafnað',
[CaseTransition.REOPEN]: ':construction: Opnað aftur',
[CaseTransition.REOPEN_APPEAL]: ':building_construction: Kæra opnuð aftur',
RESUBMIT: ':mailbox_with_mail: Sent aftur',
RECEIVE: ':eyes: Móttekið',
ACCEPT: ':white_check_mark: Samþykkt',
REJECT: ':negative_squared_cross_mark: Hafnað',
DISMISS: ':woman-shrugging: Vísað frá',
COMPLETE: ':white_check_mark: Lokið',
DELETE: ':fire: Afturkallað',
[CaseTransition.RETURN_INDICTMENT]: ':woman-gesturing-no: Ákæru afturkallað',
SCHEDULE_COURT_DATE: ':timer_clock: Fyrirtökutíma úthlutað',
ARCHIVE: ':file_cabinet: Sett í geymslu',
REOPEN: ':construction: Opnað aftur',
APPEAL: ':judge: Kæra',
RECEIVE_APPEAL: ':eyes: Kæra móttekin',
COMPLETE_APPEAL: ':white_check_mark: Kæru lokið',
REOPEN_APPEAL: ':building_construction: Kæra opnuð aftur',
[CaseTransition.SUBMIT]: ':mailbox_with_mail: Sent',
[CaseTransition.WITHDRAW_APPEAL]:
':leftwards_arrow_with_hook: Kæru afturkallað',
}

export enum CaseEvent {
CREATE = 'CREATE',
CREATE_XRD = 'CREATE_XRD',
EXTEND = 'EXTEND',
OPEN = 'OPEN',
ASK_FOR_CONFIRMATION = 'ASK_FOR_CONFIRMATION',
SUBMIT = 'SUBMIT',
RESUBMIT = 'RESUBMIT',
RECEIVE = 'RECEIVE',
ACCEPT = 'ACCEPT',
REJECT = 'REJECT',
DELETE = 'DELETE',
SCHEDULE_COURT_DATE = 'SCHEDULE_COURT_DATE',
DISMISS = 'DISMISS',
ARCHIVE = 'ARCHIVE',
REOPEN = 'REOPEN',
APPEAL = 'APPEAL',
RECEIVE_APPEAL = 'RECEIVE_APPEAL',
COMPLETE_APPEAL = 'COMPLETE_APPEAL',
REOPEN_APPEAL = 'REOPEN_APPEAL',
}
export type CaseEvent =
| CaseTransition
| 'ARCHIVE'
| 'CREATE'
| 'CREATE_XRD'
| 'EXTEND'
| 'RESUBMIT'
| 'SCHEDULE_COURT_DATE'

@Injectable()
export class EventService {
Expand Down Expand Up @@ -120,7 +115,7 @@ export class EventService {
? `\n>Landsréttur *${theCase.appealCaseNumber}*`
: ''
const extraText =
event === CaseEvent.SCHEDULE_COURT_DATE
event === 'SCHEDULE_COURT_DATE'
? `\n>Dómari ${
theCase.judge?.name ?? 'er ekki skráður'
}\n>Dómritari ${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ export class InternalNotificationService extends BaseNotificationService {
} else if (theCase.state === CaseState.RECEIVED) {
promises.push(this.sendResubmittedToCourtSmsNotificationToCourt(theCase))

this.eventService.postEvent(CaseEvent.RESUBMIT, theCase)
this.eventService.postEvent('RESUBMIT', theCase)
}

if (
Expand Down Expand Up @@ -768,7 +768,7 @@ export class InternalNotificationService extends BaseNotificationService {
theCase: Case,
user: User,
): Promise<DeliverResponse> {
this.eventService.postEvent(CaseEvent.SCHEDULE_COURT_DATE, theCase)
this.eventService.postEvent('SCHEDULE_COURT_DATE', theCase)

const promises: Promise<Recipient>[] = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ export class NotificationService {
break
case NotificationType.COURT_DATE:
if (eventOnly) {
this.eventService.postEvent(
CaseEvent.SCHEDULE_COURT_DATE,
theCase,
true,
)
this.eventService.postEvent('SCHEDULE_COURT_DATE', theCase, true)

// We still want to send the defender a link to the case even if
// the judge chooses not to send a calendar invitation
Expand Down
44 changes: 22 additions & 22 deletions libs/judicial-system/types/src/lib/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,50 +132,50 @@ export enum CaseAppealState {
}

export enum CaseTransition {
OPEN = 'OPEN',
ACCEPT = 'ACCEPT',
APPEAL = 'APPEAL',
ASK_FOR_CANCELLATION = 'ASK_FOR_CANCELLATION',
ASK_FOR_CONFIRMATION = 'ASK_FOR_CONFIRMATION',
COMPLETE = 'COMPLETE',
COMPLETE_APPEAL = 'COMPLETE_APPEAL',
DELETE = 'DELETE',
DENY_INDICTMENT = 'DENY_INDICTMENT',
SUBMIT = 'SUBMIT',
ASK_FOR_CANCELLATION = 'ASK_FOR_CANCELLATION',
DISMISS = 'DISMISS',
OPEN = 'OPEN',
RECEIVE = 'RECEIVE',
RETURN_INDICTMENT = 'RETURN_INDICTMENT',
COMPLETE = 'COMPLETE',
ACCEPT = 'ACCEPT',
RECEIVE_APPEAL = 'RECEIVE_APPEAL',
REJECT = 'REJECT',
DISMISS = 'DISMISS',
DELETE = 'DELETE',
REOPEN = 'REOPEN',
APPEAL = 'APPEAL',
RECEIVE_APPEAL = 'RECEIVE_APPEAL',
COMPLETE_APPEAL = 'COMPLETE_APPEAL',
REOPEN_APPEAL = 'REOPEN_APPEAL',
RETURN_INDICTMENT = 'RETURN_INDICTMENT',
SUBMIT = 'SUBMIT',
WITHDRAW_APPEAL = 'WITHDRAW_APPEAL',
}

export enum IndictmentCaseTransition {
ASK_FOR_CANCELLATION = CaseTransition.ASK_FOR_CANCELLATION,
ASK_FOR_CONFIRMATION = CaseTransition.ASK_FOR_CONFIRMATION,
COMPLETE = CaseTransition.COMPLETE,
DELETE = CaseTransition.DELETE,
DENY_INDICTMENT = CaseTransition.DENY_INDICTMENT,
SUBMIT = CaseTransition.SUBMIT,
ASK_FOR_CANCELLATION = CaseTransition.ASK_FOR_CANCELLATION,
RECEIVE = CaseTransition.RECEIVE,
RETURN_INDICTMENT = CaseTransition.RETURN_INDICTMENT,
COMPLETE = CaseTransition.COMPLETE,
DELETE = CaseTransition.DELETE,
SUBMIT = CaseTransition.SUBMIT,
}

export enum RequestCaseTransition {
ACCEPT = CaseTransition.ACCEPT,
APPEAL = CaseTransition.APPEAL,
COMPLETE_APPEAL = CaseTransition.COMPLETE_APPEAL,
DELETE = CaseTransition.DELETE,
DISMISS = CaseTransition.DISMISS,
OPEN = CaseTransition.OPEN,
SUBMIT = CaseTransition.SUBMIT,
RECEIVE = CaseTransition.RECEIVE,
ACCEPT = CaseTransition.ACCEPT,
RECEIVE_APPEAL = CaseTransition.RECEIVE_APPEAL,
REJECT = CaseTransition.REJECT,
DISMISS = CaseTransition.DISMISS,
DELETE = CaseTransition.DELETE,
REOPEN = CaseTransition.REOPEN,
APPEAL = CaseTransition.APPEAL,
RECEIVE_APPEAL = CaseTransition.RECEIVE_APPEAL,
COMPLETE_APPEAL = CaseTransition.COMPLETE_APPEAL,
REOPEN_APPEAL = CaseTransition.REOPEN_APPEAL,
SUBMIT = CaseTransition.SUBMIT,
WITHDRAW_APPEAL = CaseTransition.WITHDRAW_APPEAL,
}

Expand Down

0 comments on commit 4f1a362

Please sign in to comment.