Skip to content

Commit

Permalink
fix(j-s): Digital mailbox API (#16301)
Browse files Browse the repository at this point in the history
* feat(j-s): Block create subpoena on staging and dev

* Update subpoena.service.ts

* fix(j-s): Fix mailbox API

* remove changes not meant for this branch

* Update subpoena.service.ts

* fix(j-s): reverting changes from other branch

* Update subpoena.response.ts

* Update subpoena.response.ts

* Update subpoena.response.ts

* Update subpoena.response.ts

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
unakb and kodiakhq[bot] authored Oct 7, 2024
1 parent ef8b3ef commit 362f331
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
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))
}

0 comments on commit 362f331

Please sign in to comment.