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

feat(j-s): Return subpoena info from digital mailbox API #15306

Merged
merged 8 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ export class InternalCaseService {
{ model: Institution, as: 'prosecutorsOffice' },
{ model: User, as: 'judge' },
{ model: User, as: 'prosecutor' },
{ model: DateLog, as: 'dateLogs' },
],
attributes: ['courtCaseNumber', 'id'],
where: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { ApiProperty } from '@nestjs/swagger'

import { InternalCaseResponse } from './internal/internalCase.response'

class Items {
@ApiProperty({ type: String })
label!: string
import { formatDate } from '@island.is/judicial-system/formatters'
import { DateType } from '@island.is/judicial-system/types'

@ApiProperty({ type: String })
value?: string

@ApiProperty({ type: String, enum: ['email', 'tel'] })
linkType?: 'email' | 'tel'
}

class Groups {
@ApiProperty({ type: String })
label!: string

@ApiProperty({ type: [Items] })
items!: Items[]
}
import { InternalCaseResponse } from './internal/internalCase.response'
import { Groups } from './shared/groups.model'
import { getTranslations } from './utils/translations.strings'
unakb marked this conversation as resolved.
Show resolved Hide resolved

class IndictmentCaseData {
@ApiProperty({ type: String })
Expand All @@ -40,80 +26,67 @@ export class CaseResponse {
res: InternalCaseResponse,
lang?: string,
): CaseResponse {
const language = lang?.toLowerCase()
const t = getTranslations(lang)
const defendant = res.defendants[0]
const subpoenaDateLog = res.dateLogs?.find(
(dateLog) => dateLog.dateType === DateType.ARRAIGNMENT_DATE,
)
const subpoenaCreatedDate = subpoenaDateLog?.created.toString() ?? ''

return {
caseId: res.id,
data: {
caseNumber:
language === 'en'
? `Case number ${res.courtCaseNumber}`
: `Málsnúmer ${res.courtCaseNumber}`,
caseNumber: `${t.caseNumber} ${res.courtCaseNumber}`,
groups: [
{
label: language === 'en' ? 'Defendant' : 'Varnaraðili',
label: t.defendant,
items: [
[language === 'en' ? 'Name' : 'Nafn', defendant.name],
[
language === 'en' ? 'National ID' : 'Kennitala',
defendant.nationalId,
],
[
language === 'en' ? 'Address' : 'Heimilisfang',
defendant.address,
],
[t.name, defendant.name],
[t.nationalId, defendant.nationalId],
[t.address, defendant.address],
[t.subpoenaSent, formatDate(subpoenaCreatedDate, 'PP')],
].map((item) => ({
label: item[0] ?? '',
value: item[1] ?? (language === 'en' ? 'N/A' : 'Ekki skráð'),
value: item[1] ?? t.notAvailable,
})),
},
{
label: language === 'en' ? 'Defender' : 'Verjandi',
label: t.defender,
items: [
[language === 'en' ? 'Name' : 'Nafn', defendant.defenderName],
[
language === 'en' ? 'Email' : 'Netfang',
defendant.defenderEmail,
'email',
],
[
language === 'en' ? 'Phone Nr.' : 'Símanúmer',
defendant.defenderPhoneNumber,
'tel',
],
[t.name, defendant.defenderName],
[t.email, defendant.defenderEmail, 'email'],
[t.phoneNumber, defendant.defenderPhoneNumber, 'tel'],
].map((item) => ({
label: item[0] ?? '',
value: item[1] ?? (language === 'en' ? 'N/A' : 'Ekki skráð'),
value: item[1] ?? t.notAvailable,
linkType: item[2] ?? undefined,
})),
},
{
label: language === 'en' ? 'Information' : 'Málsupplýsingar',
label: t.information,
items: [
{
label: language === 'en' ? 'Type' : 'Tegund',
value: language === 'en' ? 'Indictment' : 'Ákæra',
label: t.type,
value: t.indictment,
},
{
label:
language === 'en' ? 'Case number' : 'Málsnúmer héraðsdóms',
label: t.courtCaseNumber,
value: res.courtCaseNumber,
},
{
label: language === 'en' ? 'Court' : 'Dómstóll',
label: t.court,
value: res.court.name,
},
{
label: language === 'en' ? 'Judge' : 'Dómari',
label: t.judge,
value: res.judge.name,
},
{
label: language === 'en' ? 'Institution' : 'Embætti',
label: t.institution,
value: res.prosecutorsOffice.name,
},
{
label: language === 'en' ? 'Prosecutor' : 'Ákærandi',
label: t.prosecutor,
value: res.prosecutor.name,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ApiProperty } from '@nestjs/swagger'
import { isCompletedCase } from '@island.is/judicial-system/types'

import { InternalCasesResponse } from './internal/internalCases.response'
import { getTranslations } from './utils/translations.strings'

export class CasesResponse {
@ApiProperty({ type: String })
Expand All @@ -25,26 +26,16 @@ export class CasesResponse {
lang?: string,
): CasesResponse[] {
return response.map((item: InternalCasesResponse) => {
const language = lang?.toLowerCase()
const t = getTranslations(lang)

return {
id: item.id,
state: {
color: isCompletedCase(item.state) ? 'purple' : 'blue',
label:
language === 'en'
? isCompletedCase(item.state)
? 'Completed'
: 'Active'
: isCompletedCase(item.state)
? 'Lokið'
: 'Í vinnslu',
label: isCompletedCase(item.state) ? t.completed : t.active,
},
caseNumber:
language === 'en'
? `Case number ${item.courtCaseNumber}`
: `Málsnúmer ${item.courtCaseNumber}`,
type: language === 'en' ? 'Indictment' : 'Ákæra',
caseNumber: `${t.caseNumber} ${item.courtCaseNumber}`,
type: t.indictment,
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DateType,
DefenderChoice,
Gender,
Institution,
Expand All @@ -13,6 +14,7 @@ export class InternalCaseResponse {
judge!: User
prosecutorsOffice!: Institution
prosecutor!: User
dateLogs?: DateLog[]
}

interface Defendant {
Expand All @@ -28,3 +30,11 @@ interface Defendant {
defenderChoice?: DefenderChoice
acceptCompensationClaim?: boolean
}

interface DateLog {
id: string
created: Date
dateType: DateType
date: Date
location?: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ApiProperty } from '@nestjs/swagger'

import { Items } from './items.model'

export class Groups {
@ApiProperty({ type: String })
label!: string

@ApiProperty({ type: [Items] })
items!: Items[]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApiProperty } from '@nestjs/swagger'

export class Items {
@ApiProperty({ type: String })
label!: string

@ApiProperty({ type: String })
value?: string

@ApiProperty({ type: String, enum: ['email', 'tel'] })
linkType?: 'email' | 'tel'
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { ApiProperty } from '@nestjs/swagger'

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

import { InternalCaseResponse } from './internal/internalCase.response'
import { Groups } from './shared/groups.model'
import { getTranslations } from './utils/translations.strings'

class DefenderInfo {
@ApiProperty({ enum: () => DefenderChoice })
Expand All @@ -13,10 +18,21 @@ class DefenderInfo {
defenderName?: string
}

class SubpoenaData {
@ApiProperty({ type: () => String })
title!: string

@ApiProperty({ type: () => [Groups] })
groups!: Groups[]
}

export class SubpoenaResponse {
@ApiProperty({ type: () => String })
caseId!: string

@ApiProperty({ type: () => SubpoenaData })
data!: SubpoenaData

@ApiProperty({ type: () => DefenderInfo })
defenderInfo?: DefenderInfo

Expand All @@ -29,23 +45,62 @@ export class SubpoenaResponse {
lang?: string,
): SubpoenaResponse {
const formattedNationalId = formatNationalId(defendantNationalId)
const title = lang === 'en' ? 'Subpoena' : 'Fyrirkall' //TODO add subpoena info to response
const t = getTranslations(lang)

const defendantInfo = internalCase.defendants.find(
(defendant) =>
defendant.nationalId === formattedNationalId ||
defendant.nationalId === defendantNationalId,
)
const hasChosenDefense = defendantInfo?.defenderChoice !== undefined
const waivedRight = defendantInfo?.defenderChoice === DefenderChoice.WAIVE
const hasDefender = defendantInfo?.defenderName !== undefined
const defenseValue = waivedRight
? t.waiveRightToCounsel
: hasDefender
? defendantInfo?.defenderName
: t.notAvailable

const hasDefender = defendantInfo?.defenderChoice !== DefenderChoice.WAIVE
const subpoenaDateLog = internalCase.dateLogs?.find(
(dateLog) => dateLog.dateType === DateType.ARRAIGNMENT_DATE,
)
const arraignmentDate = subpoenaDateLog?.date ?? ''
const subpoenaCreatedDate = subpoenaDateLog?.created ?? ''

return {
caseId: internalCase.id,
data: {
title: t.subpoena,
groups: [
{
label: `${t.caseNumber} ${internalCase.courtCaseNumber}`,
items: [
[t.date, formatDate(subpoenaCreatedDate, 'PP')],
[t.institution, 'Lögreglustjórinn á höfuðborgarsvæðinu'],
[t.prosecutor, internalCase.prosecutor?.name],
[t.accused, defendantInfo?.name],
[
t.arraignmentDate,
formatDate(arraignmentDate, "d.M.yyyy 'kl.' HH:mm"),
],
[t.location, subpoenaDateLog?.location ?? ''],
[t.courtCeremony, t.parliamentaryConfirmation],
hasChosenDefense ? [t.defender, defenseValue] : [],
].map((item) => ({
label: item[0] ?? '',
value: item[1] ?? t.notAvailable,
})),
},
],
},

defenderInfo: defendantInfo
? {
defenderChoice: defendantInfo?.defenderChoice,
defenderName: hasDefender ? defendantInfo?.defenderName : undefined,
defenderName:
!waivedRight && hasDefender
? defendantInfo?.defenderName
: undefined,
}
: undefined,
acceptCompensationClaim: defendantInfo?.acceptCompensationClaim,
Expand Down
Loading
Loading