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): Separate requested defender info from actual assigned defender #16393

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -75,6 +75,15 @@ export class Defendant {
@Field(() => DefenderChoice, { nullable: true })
readonly defenderChoice?: DefenderChoice

@Field(() => DefenderChoice, { nullable: true })
readonly requestedDefenderChoice?: DefenderChoice

@Field(() => String, { nullable: true })
readonly requestedDefenderNationalId?: string

@Field(() => String, { nullable: true })
readonly requestedDefenderName?: string

@Field(() => SubpoenaType, { nullable: true })
readonly subpoenaType?: SubpoenaType

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(async (t) => {
await queryInterface.addColumn(
'defendant',
'requested_defender_choice',
{
type: Sequelize.STRING,
allowNull: true,
},
{ transaction: t },
)
await queryInterface.addColumn(
'defendant',
'requested_defender_national_id',
{
type: Sequelize.STRING,
allowNull: true,
},
{ transaction: t },
)
await queryInterface.addColumn(
'defendant',
'requested_defender_name',
{
type: Sequelize.STRING,
allowNull: true,
},
{ transaction: t },
)

await queryInterface.sequelize.query(
`UPDATE "defendant" SET requested_defender_choice = defender_choice`,
{ transaction: t },
)

await queryInterface.sequelize.query(
`UPDATE "defendant" SET requested_defender_national_id = defender_national_id`,
{ transaction: t },
)

await queryInterface.sequelize.query(
`UPDATE "defendant" SET requested_defender_name = defender_name`,
{ transaction: t },
)
unakb marked this conversation as resolved.
Show resolved Hide resolved
})
},
down: (queryInterface) => {
return queryInterface.sequelize.transaction(async (t) => {
await queryInterface.removeColumn(
'defendant',
'requested_defender_choice',
{
transaction: t,
},
)
await queryInterface.removeColumn(
'defendant',
'requested_defender_national_id',
{
transaction: t,
},
)
await queryInterface.removeColumn(
'defendant',
'requested_defender_name',
{
transaction: t,
},
)
})
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,19 @@ export class UpdateDefendantDto {
@IsEnum(SubpoenaType)
@ApiPropertyOptional({ enum: SubpoenaType })
readonly subpoenaType?: SubpoenaType

@IsOptional()
@IsEnum(DefenderChoice)
@ApiPropertyOptional({ enum: DefenderChoice })
readonly requestedDefenderChoice?: DefenderChoice

@IsOptional()
@IsString()
@ApiPropertyOptional({ type: String })
readonly requestedDefenderNationalId?: string

@IsOptional()
@IsString()
@ApiPropertyOptional({ type: String })
readonly requestedDefenderName?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,20 @@ export class Defendant extends Model {
@HasMany(() => Subpoena, { foreignKey: 'defendantId' })
@ApiPropertyOptional({ type: () => Subpoena, isArray: true })
subpoenas?: Subpoena[]

@Column({
type: DataType.ENUM,
allowNull: true,
values: Object.values(DefenderChoice),
})
@ApiPropertyOptional({ enum: DefenderChoice })
oddsson marked this conversation as resolved.
Show resolved Hide resolved
requestedDefenderChoice?: DefenderChoice

@Column({ type: DataType.STRING, allowNull: true })
@ApiPropertyOptional({ type: String })
requestedDefenderNationalId?: string

@Column({ type: DataType.STRING, allowNull: true })
@ApiPropertyOptional({ type: String })
requestedDefenderName?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@ export class UpdateSubpoenaDto {
@IsString()
@ApiPropertyOptional({ type: String })
readonly defenderPhoneNumber?: string

@IsOptional()
@IsEnum(DefenderChoice)
@ApiPropertyOptional({ enum: DefenderChoice })
readonly requestedDefenderChoice?: DefenderChoice

@IsOptional()
@IsString()
@ApiPropertyOptional({ type: String })
readonly requestedDefenderNationalId?: string

@IsOptional()
@IsString()
@ApiPropertyOptional({ type: String })
readonly requestedDefenderName?: string
unakb marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
type User,
} from '@island.is/judicial-system/types'

import { indictment } from '../../messages'
import { Case } from '../case/models/case.model'
import { PdfService } from '../case/pdf.service'
import { Defendant } from '../defendant/models/defendant.model'
Expand Down Expand Up @@ -93,6 +92,9 @@ export class SubpoenaService {
defenderEmail,
defenderPhoneNumber,
defenderName,
requestedDefenderChoice,
requestedDefenderNationalId,
requestedDefenderName,
} = update

const [numberOfAffectedRows] = await this.subpoenaModel.update(update, {
Expand All @@ -102,13 +104,21 @@ export class SubpoenaService {
})
let defenderAffectedRows = 0

if (defenderChoice || defenderNationalId) {
if (
defenderChoice ||
defenderNationalId ||
requestedDefenderChoice ||
requestedDefenderNationalId
) {
const defendantUpdate: Partial<Defendant> = {
defenderChoice,
defenderNationalId,
defenderName,
defenderEmail,
defenderPhoneNumber,
requestedDefenderChoice,
requestedDefenderNationalId,
requestedDefenderName,
}

const [defenderUpdateAffectedRows] = await this.defendantModel.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,15 @@ export class CaseService {
defenderAssignment: UpdateSubpoenaDto,
lang?: string,
): Promise<SubpoenaResponse> {
let defenderChoice = { ...defenderAssignment }

let chosenLawyer = null
if (defenderAssignment.defenderChoice === DefenderChoice.CHOOSE) {
if (!defenderAssignment.defenderNationalId) {
throw new NotFoundException(
'Defender national id is required for choice',
)
}

const chosenLawyer = await this.lawyersService.getLawyer(
chosenLawyer = await this.lawyersService.getLawyer(
defenderAssignment.defenderNationalId,
)

Expand All @@ -135,20 +134,16 @@ export class CaseService {
'Selected lawyer was not found in the lawyer registry',
)
}

defenderChoice = {
...defenderChoice,
...{
defenderName: chosenLawyer.Name,
defenderEmail: chosenLawyer.Email,
defenderPhoneNumber: chosenLawyer.Phone,
},
}
}

await this.patchSubpoenaInfo(defendantNationalId, caseId, defenderChoice)

const defenderChoice = {
requestedDefenderChoice: defenderAssignment.defenderChoice,
requestedDefenderNationalId: defenderAssignment.defenderNationalId,
requestedDefenderName: chosenLawyer?.Name,
}
await this.patchDefenseInfo(defendantNationalId, caseId, defenderChoice)
const updatedCase = await this.fetchCase(caseId, defendantNationalId)

return SubpoenaResponse.fromInternalCaseResponse(
updatedCase,
defendantNationalId,
Expand Down Expand Up @@ -230,10 +225,14 @@ export class CaseService {
}
}

private async patchSubpoenaInfo(
private async patchDefenseInfo(
defendantNationalId: string,
caseId: string,
defenderChoice: UpdateSubpoenaDto,
defenderChoice: {
requestedDefenderChoice: DefenderChoice
requestedDefenderNationalId: string | undefined
requestedDefenderName?: string
},
): Promise<InternalDefendantResponse> {
try {
const response = await fetch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ interface Defendant {
defenderPhoneNumber?: string
defenderChoice?: DefenderChoice
subpoenas?: Subpoena[]
requestedDefenderChoice?: DefenderChoice
requestedDefenderNationalId?: string
requestedDefenderName?: string
}

interface DateLog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ export class InternalDefendantResponse {
id!: string
defenderChoice?: DefenderChoice
defenderName?: string
requestedDefenderChoice?: DefenderChoice
requestedDefenderNationalId?: string
requestedDefenderName?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ export class SubpoenaResponse {
),
)

const waivedRight = defendantInfo?.defenderChoice === DefenderChoice.WAIVE
const hasDefender = defendantInfo?.defenderName !== null
const waivedRight =
defendantInfo?.requestedDefenderChoice === DefenderChoice.WAIVE
const hasDefender = defendantInfo?.requestedDefenderNationalId !== null
unakb marked this conversation as resolved.
Show resolved Hide resolved
const subpoenas = defendantInfo?.subpoenas ?? []
const hasBeenServed =
subpoenas.length > 0 &&
Expand All @@ -121,8 +122,8 @@ export class SubpoenaResponse {
subtitle: courtNameAndAddress,
hasBeenServed: hasBeenServed,
hasChosenDefender: Boolean(
defendantInfo?.defenderChoice &&
defendantInfo.defenderChoice !== DefenderChoice.DELAY,
defendantInfo?.requestedDefenderChoice &&
defendantInfo.requestedDefenderChoice !== DefenderChoice.DELAY,
unakb marked this conversation as resolved.
Show resolved Hide resolved
),
defaultDefenderChoice: DefenderChoice.DELAY,
alerts: [
Expand Down Expand Up @@ -160,12 +161,12 @@ export class SubpoenaResponse {
],
},

defenderInfo: defendantInfo?.defenderChoice
defenderInfo: defendantInfo?.requestedDefenderChoice
? {
defenderChoice: defendantInfo?.defenderChoice,
defenderChoice: defendantInfo?.requestedDefenderChoice,
defenderName:
!waivedRight && hasDefender
? defendantInfo?.defenderName
? defendantInfo?.requestedDefenderName
unakb marked this conversation as resolved.
Show resolved Hide resolved
: undefined,
canEdit: canChangeDefenseChoice,
courtContactInfo: canChangeDefenseChoice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ query Case($input: CaseQueryInput!) {
defenderPhoneNumber
defenderChoice
defendantPlea
requestedDefenderChoice
requestedDefenderNationalId
requestedDefenderName
serviceRequirement
verdictViewDate
verdictAppealDeadline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,17 @@ export const strings = defineMessages({
description:
'Notaður sem texti þegar enginn lögmaður er skráður í dómaraflæði í ákærum.',
},
defenderChoiceAlertTitle: {
id: 'judicial.system.core:court_indictments.advocates.defender_choice_alert_title',
defaultMessage: 'Val á verjanda - {defendantName}',
description:
'Notaður sem texti þegar ákærði hefur valið verjanda í dómaraflæði í ákærum.',
},
defenderChoiceAlertMessage: {
id: 'judicial.system.core:court_indictments.advocates.defender_choice_alert_message',
defaultMessage:
'{requestedDefenderChoice, select, WAIVE {Ég óska ekki eftir verjanda.} CHOOSE {Ég óska þess að valinn lögmaður verji skipaður verjandi minn: {requestedDefenderName} kt. {requestedDefenderNationalId}.} DELAY {Ég óska eftir fresti fram að þingfestingu til þess að tilnefna verjanda.} DELEGATE {Ég fel dómara málsins að tilnefna og skipa mér verjanda.} other {Ekkert valið.}}',
description:
'Notaður sem texti þegar ákærði hefur valið verjanda í dómaraflæði í ákærum.',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ const Advocates = () => {
message={formatMessage(strings.alertBannerText)}
type="info"
/>
{workingCase.defendants
?.filter((defendant) => defendant.requestedDefenderChoice)
.map((defendant) => (
<Box marginTop={2}>
<AlertMessage
title={formatMessage(strings.defenderChoiceAlertTitle, {
defendantName: defendant.name,
})}
message={formatMessage(strings.defenderChoiceAlertMessage, {
requestedDefenderChoice: defendant.requestedDefenderChoice,
requestedDefenderName: defendant.requestedDefenderName,
requestedDefenderNationalId:
defendant.requestedDefenderNationalId,
})}
type="warning"
/>
</Box>
))}
unakb marked this conversation as resolved.
Show resolved Hide resolved
</Box>
<Box component="section" marginBottom={hasCivilClaimants ? 5 : 10}>
<SectionHeading
Expand Down
Loading
Loading