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

fix(j-s): Digital mailbox API #16301

Merged
merged 13 commits into from
Oct 7, 2024
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Base } from 'infra/src/dsl/xroad'
import { Base64 } from 'js-base64'
import { Includeable, Sequelize } from 'sequelize'
import { Transaction } from 'sequelize/types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { ApiProperty } from '@nestjs/swagger'

import { formatDate } from '@island.is/judicial-system/formatters'
import { DateType } from '@island.is/judicial-system/types'
import {
DateType,
isSuccessfulServiceStatus,
} from '@island.is/judicial-system/types'

import { InternalCaseResponse } from './internal/internalCase.response'
import { Groups } from './shared/groups.model'
Expand Down Expand Up @@ -41,7 +44,10 @@ export class CaseResponse {
caseId: internalCase.id,
data: {
caseNumber: `${t.caseNumber} ${internalCase.courtCaseNumber}`,
hasBeenServed: subpoenas.length > 0 ? subpoenas[0].acknowledged : false,
hasBeenServed:
subpoenas.length > 0
? isSuccessfulServiceStatus(subpoenas[0].serviceStatus)
: false,
groups: [
{
label: t.defendant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DefenderChoice,
Gender,
Institution,
ServiceStatus,
User,
} from '@island.is/judicial-system/types'

Expand Down Expand Up @@ -42,5 +43,5 @@ interface DateLog {
interface Subpoena {
id: string
subpoenaId: string
acknowledged: boolean
serviceStatus?: ServiceStatus
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {
formatDate,
normalizeAndFormatNationalId,
} from '@island.is/judicial-system/formatters'
import { DateType, DefenderChoice } from '@island.is/judicial-system/types'
import {
DateType,
DefenderChoice,
isSuccessfulServiceStatus,
} from '@island.is/judicial-system/types'

import { InternalCaseResponse } from './internal/internalCase.response'
import { Groups } from './shared/groups.model'
Expand Down Expand Up @@ -59,6 +63,12 @@ class SubpoenaData {

@ApiProperty({ type: Boolean })
hasBeenServed?: boolean

@ApiProperty({ type: Boolean })
hasChosenDefender?: boolean

@ApiProperty({ enum: DefenderChoice })
defaultDefenderChoice?: DefenderChoice
}

export class SubpoenaResponse {
Expand Down Expand Up @@ -87,9 +97,11 @@ export class SubpoenaResponse {
)

const waivedRight = defendantInfo?.defenderChoice === DefenderChoice.WAIVE
const hasDefender = defendantInfo?.defenderName !== undefined
const subpoena = defendantInfo?.subpoenas ?? []
const hasBeenServed = subpoena[0]?.acknowledged ?? false
const hasDefender = defendantInfo?.defenderName !== null
const subpoenas = defendantInfo?.subpoenas ?? []
const hasBeenServed =
subpoenas.length > 0 &&
isSuccessfulServiceStatus(subpoenas[0].serviceStatus)
const canChangeDefenseChoice = !waivedRight && !hasDefender

const subpoenaDateLog = internalCase.dateLogs?.find(
Expand All @@ -108,6 +120,11 @@ export class SubpoenaResponse {
title: t.subpoena,
subtitle: courtNameAndAddress,
hasBeenServed: hasBeenServed,
hasChosenDefender: Boolean(
defendantInfo?.defenderChoice &&
defendantInfo.defenderChoice !== DefenderChoice.DELAY,
),
defaultDefenderChoice: DefenderChoice.DELAY,
alerts: [
...(hasBeenServed
? [
Expand Down
1 change: 1 addition & 0 deletions libs/judicial-system/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
DefendantPlea,
ServiceRequirement,
ServiceStatus,
isSuccessfulServiceStatus,
} from './lib/defendant'
export { InstitutionType } from './lib/institution'
export { NotificationType } from './lib/notification'
Expand Down
10 changes: 10 additions & 0 deletions libs/judicial-system/types/src/lib/defendant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ export enum ServiceStatus {
FAILED = 'FAILED',
EXPIRED = 'EXPIRED', // If a subpoena expires
}

export const successfulServiceStatus: string[] = [
ServiceStatus.ELECTRONICALLY,
ServiceStatus.DEFENDER,
ServiceStatus.IN_PERSON,
]

export const isSuccessfulServiceStatus = (status?: ServiceStatus): boolean => {
return Boolean(status && successfulServiceStatus.includes(status))
}
Loading