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 2e735bcf6367..179b3ae41d3a 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 @@ -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' diff --git a/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/case.response.ts b/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/case.response.ts index 7889f054a2e9..6398f668c5e7 100644 --- a/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/case.response.ts +++ b/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/case.response.ts @@ -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' @@ -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, diff --git a/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/internal/internalCase.response.ts b/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/internal/internalCase.response.ts index 72bd4ccfa847..efff1d029dd3 100644 --- a/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/internal/internalCase.response.ts +++ b/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/internal/internalCase.response.ts @@ -3,6 +3,7 @@ import { DefenderChoice, Gender, Institution, + ServiceStatus, User, } from '@island.is/judicial-system/types' @@ -42,5 +43,5 @@ interface DateLog { interface Subpoena { id: string subpoenaId: string - acknowledged: boolean + serviceStatus?: ServiceStatus } diff --git a/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/subpoena.response.ts b/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/subpoena.response.ts index 342e0ed294f5..0c432b55b5b5 100644 --- a/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/subpoena.response.ts +++ b/apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/subpoena.response.ts @@ -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' @@ -59,6 +63,12 @@ class SubpoenaData { @ApiProperty({ type: Boolean }) hasBeenServed?: boolean + + @ApiProperty({ type: Boolean }) + hasChosenDefender?: boolean + + @ApiProperty({ enum: DefenderChoice }) + defaultDefenderChoice?: DefenderChoice } export class SubpoenaResponse { @@ -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( @@ -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 ? [ diff --git a/libs/judicial-system/types/src/index.ts b/libs/judicial-system/types/src/index.ts index 899aa61fe4b4..29817dad0bf6 100644 --- a/libs/judicial-system/types/src/index.ts +++ b/libs/judicial-system/types/src/index.ts @@ -7,6 +7,7 @@ export { DefendantPlea, ServiceRequirement, ServiceStatus, + isSuccessfulServiceStatus, } from './lib/defendant' export { InstitutionType } from './lib/institution' export { NotificationType } from './lib/notification' diff --git a/libs/judicial-system/types/src/lib/defendant.ts b/libs/judicial-system/types/src/lib/defendant.ts index 5994ab09f293..be51efe47cef 100644 --- a/libs/judicial-system/types/src/lib/defendant.ts +++ b/libs/judicial-system/types/src/lib/defendant.ts @@ -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)) +}