From 185497036b555d506c8fec531b6efab25b507c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Thu, 28 Nov 2024 19:29:15 +0000 Subject: [PATCH] Validates date of birth in national id fields allowin null values --- .../src/app/formatters/indictmentPdf.ts | 17 +++--- .../src/app/modules/case/case.service.ts | 8 +-- .../transformers/nationalId.transformer.ts | 13 +++-- .../src/components/Inputs/InputAdvocate.tsx | 54 ++++++++++++------- .../src/components/Inputs/InputNationalId.tsx | 7 ++- .../Indictments/Defendant/Defendant.tsx | 8 +-- .../Indictments/Processing/Processing.tsx | 6 +-- .../InvestigationCase/Defendant/Defendant.tsx | 4 +- .../RestrictionCase/Defendant/Defendant.tsx | 2 +- .../DefendantInfo/DefendantInfo.tsx | 4 +- .../judicial-system/web/src/utils/validate.ts | 20 ++++--- 11 files changed, 81 insertions(+), 62 deletions(-) diff --git a/apps/judicial-system/backend/src/app/formatters/indictmentPdf.ts b/apps/judicial-system/backend/src/app/formatters/indictmentPdf.ts index 0279dbb208f9..f6ac73e56483 100644 --- a/apps/judicial-system/backend/src/app/formatters/indictmentPdf.ts +++ b/apps/judicial-system/backend/src/app/formatters/indictmentPdf.ts @@ -113,16 +113,13 @@ export const createIndictment = async ( addEmptyLines(doc, 2) addNormalPlusCenteredText( doc, - formatMessage( - indictment.signature, - { - prosecutorsOfficeName: - lowercase(theCase.prosecutorsOffice?.name) - .replace('lögreglustjórinn', 'lögreglustjórans') - .replace('saksóknari', 'saksóknara') ?? '', - date: formatDate(nowFactory(), 'PPP'), - } ?? '', - ), + formatMessage(indictment.signature, { + prosecutorsOfficeName: + lowercase(theCase.prosecutorsOffice?.name) + .replace('lögreglustjórinn', 'lögreglustjórans') + .replace('saksóknari', 'saksóknara') ?? '', + date: formatDate(nowFactory(), 'PPP'), + }), ) doc.end() diff --git a/apps/judicial-system/backend/src/app/modules/case/case.service.ts b/apps/judicial-system/backend/src/app/modules/case/case.service.ts index 5cff475da8fd..9a671f3ba761 100644 --- a/apps/judicial-system/backend/src/app/modules/case/case.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/case.service.ts @@ -183,13 +183,13 @@ export interface UpdateCase courtRecordSignatoryId?: string | null courtRecordSignatureDate?: Date | null parentCaseId?: string | null - arraignmentDate?: UpdateDateLog | null - courtDate?: UpdateDateLog | null - postponedIndefinitelyExplanation?: string | null indictmentReturnedExplanation?: string | null indictmentDeniedExplanation?: string | null indictmentHash?: string | null - civilDemands?: string | null + arraignmentDate?: UpdateDateLog + courtDate?: UpdateDateLog + postponedIndefinitelyExplanation?: string + civilDemands?: string } type DateLogKeys = keyof Pick diff --git a/apps/judicial-system/backend/src/app/transformers/nationalId.transformer.ts b/apps/judicial-system/backend/src/app/transformers/nationalId.transformer.ts index deb6b41a5aac..9a2d80ac6444 100644 --- a/apps/judicial-system/backend/src/app/transformers/nationalId.transformer.ts +++ b/apps/judicial-system/backend/src/app/transformers/nationalId.transformer.ts @@ -1,8 +1,13 @@ interface Value { - value?: string + value?: string | null } -type NationalIdTransformer = ({ value }: Value) => string | undefined +type NationalIdTransformer = ({ value }: Value) => string | undefined | null -export const nationalIdTransformer: NationalIdTransformer = ({ value }) => - value?.replace(/-/g, '') +export const nationalIdTransformer: NationalIdTransformer = ({ value }) => { + if (!value) { + return value + } + + return value.replace(/-/g, '') +} diff --git a/apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx b/apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx index 75206b7d7e37..106c0723969e 100644 --- a/apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx +++ b/apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx @@ -51,6 +51,20 @@ interface PropertyValidation { } } +interface LawyerUpdate { + defenderName: string | null + defenderNationalId: string | null + defenderEmail: string | null + defenderPhoneNumber: string | null +} + +interface SpokespersonUpdate { + spokespersonName: string | null + spokespersonNationalId: string | null + spokespersonEmail: string | null + spokespersonPhoneNumber: string | null +} + type InputType = | 'defenderEmail' | 'defenderPhoneNumber' @@ -123,18 +137,18 @@ const InputAdvocate: FC = ({ isCivilClaim: boolean, clientId?: string | null, ) => { - let updatedLawyer = { - defenderName: '', - defenderNationalId: '', - defenderEmail: '', - defenderPhoneNumber: '', + let updatedLawyer: LawyerUpdate = { + defenderName: null, + defenderNationalId: null, + defenderEmail: null, + defenderPhoneNumber: null, } - let updatedSpokesperson = { - spokespersonName: '', - spokespersonNationalId: '', - spokespersonEmail: '', - spokespersonPhoneNumber: '', + let updatedSpokesperson: SpokespersonUpdate = { + spokespersonName: null, + spokespersonNationalId: null, + spokespersonEmail: null, + spokespersonPhoneNumber: null, } if (selectedOption) { @@ -147,16 +161,16 @@ const InputAdvocate: FC = ({ ) updatedLawyer = { defenderName: lawyer ? lawyer.name : label, - defenderNationalId: lawyer ? lawyer.nationalId : '', - defenderEmail: lawyer ? lawyer.email : '', - defenderPhoneNumber: lawyer ? lawyer.phoneNr : '', + defenderNationalId: lawyer ? lawyer.nationalId : null, + defenderEmail: lawyer ? lawyer.email : null, + defenderPhoneNumber: lawyer ? lawyer.phoneNr : null, } updatedSpokesperson = { spokespersonName: lawyer ? lawyer.name : label, - spokespersonNationalId: lawyer ? lawyer.nationalId : '', - spokespersonEmail: lawyer ? lawyer.email : '', - spokespersonPhoneNumber: lawyer ? lawyer.phoneNr : '', + spokespersonNationalId: lawyer ? lawyer.nationalId : null, + spokespersonEmail: lawyer ? lawyer.email : null, + spokespersonPhoneNumber: lawyer ? lawyer.phoneNr : null, } } @@ -226,17 +240,17 @@ const InputAdvocate: FC = ({ switch (property) { case 'defenderEmail': { return { - defenderEmail: value, + defenderEmail: value || null, } } case 'defenderPhoneNumber': { - return { defenderPhoneNumber: value } + return { defenderPhoneNumber: value || null } } case 'spokespersonEmail': { - return { spokespersonEmail: value } + return { spokespersonEmail: value || null } } case 'spokespersonPhoneNumber': { - return { spokespersonPhoneNumber: value } + return { spokespersonPhoneNumber: value || null } } } }, []) diff --git a/apps/judicial-system/web/src/components/Inputs/InputNationalId.tsx b/apps/judicial-system/web/src/components/Inputs/InputNationalId.tsx index b737255e67c0..0489d37fb744 100644 --- a/apps/judicial-system/web/src/components/Inputs/InputNationalId.tsx +++ b/apps/judicial-system/web/src/components/Inputs/InputNationalId.tsx @@ -50,16 +50,15 @@ const InputNationalId: FC = (props) => { const inputValidator = validate([ [ evt.target.value, - isDateOfBirth ? ['date-of-birth'] : ['empty', 'national-id'], ], ]) - if (!required) { - onBlur(inputValue) - } else if (inputValidator.isValid) { + if (inputValidator.isValid) { setErrorMessage(undefined) onBlur(inputValue) + } else if (!required && !evt.target.value) { + onBlur(inputValue) } else { setErrorMessage(inputValidator.errorMessage) } diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx index fc2b4b10cbd2..2bae92a4bbd9 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx @@ -351,7 +351,7 @@ const Defendant = () => { gender: defendant.gender, name: defendant.name, address: defendant.address, - nationalId: defendant.nationalId, + nationalId: defendant.nationalId || null, noNationalId: defendant.noNationalId, citizenship: defendant.citizenship, }) @@ -361,7 +361,7 @@ const Defendant = () => { gender: defendant.gender, name: defendant.name, address: defendant.address, - nationalId: defendant.nationalId, + nationalId: defendant.nationalId || null, noNationalId: defendant.noNationalId, citizenship: defendant.citizenship, }) @@ -421,7 +421,7 @@ const Defendant = () => { gender: undefined, name: '', address: '', - nationalId: '', + nationalId: null, citizenship: '', }) @@ -442,7 +442,7 @@ const Defendant = () => { id: defendantId || uuid(), gender: undefined, name: '', - nationalId: '', + nationalId: null, address: '', citizenship: '', } as TDefendant, diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx index f7b17f45e9e1..b46712f2e366 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx @@ -75,7 +75,7 @@ const Processing: FC = () => { const router = useRouter() const isTrafficViolationCaseCheck = isTrafficViolationCase(workingCase) const [civilClaimantNationalIdUpdate, setCivilClaimantNationalIdUpdate] = - useState<{ nationalId: string; civilClaimantId: string }>() + useState<{ nationalId: string | null; civilClaimantId: string }>() const [hasCivilClaimantChoice, setHasCivilClaimantChoice] = useState() const [nationalIdNotFound, setNationalIdNotFound] = useState(false) @@ -187,12 +187,12 @@ const Processing: FC = () => { handleUpdateCivilClaimant({ caseId: workingCase.id, civilClaimantId, - nationalId, + nationalId: nationalId || null, }) } else { const cleanNationalId = nationalId ? nationalId.replace('-', '') : '' setCivilClaimantNationalIdUpdate({ - nationalId: cleanNationalId, + nationalId: cleanNationalId || null, civilClaimantId, }) } diff --git a/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx b/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx index 2470cb389ec4..2be75ba20374 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx @@ -94,7 +94,7 @@ const Defendant = () => { gender: defendant.gender, name: defendant.name, address: defendant.address, - nationalId: defendant.nationalId, + nationalId: defendant.nationalId || null, noNationalId: defendant.noNationalId, citizenship: defendant.citizenship, }) @@ -104,7 +104,7 @@ const Defendant = () => { gender: defendant.gender, name: defendant.name, address: defendant.address, - nationalId: defendant.nationalId, + nationalId: defendant.nationalId || null, noNationalId: defendant.noNationalId, citizenship: defendant.citizenship, }) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/Defendant/Defendant.tsx b/apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/Defendant/Defendant.tsx index b7e0f94d90e4..44fe9de9b4d6 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/Defendant/Defendant.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/Defendant/Defendant.tsx @@ -107,7 +107,7 @@ export const Defendant = () => { gender: workingCase.defendants[0].gender, name: workingCase.defendants[0].name, address: workingCase.defendants[0].address, - nationalId: workingCase.defendants[0].nationalId, + nationalId: workingCase.defendants[0].nationalId || null, noNationalId: workingCase.defendants[0].noNationalId, citizenship: workingCase.defendants[0].citizenship, }) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/components/DefendantInfo/DefendantInfo.tsx b/apps/judicial-system/web/src/routes/Prosecutor/components/DefendantInfo/DefendantInfo.tsx index ab612e15b6c0..3e4149d6dfb1 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/components/DefendantInfo/DefendantInfo.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/components/DefendantInfo/DefendantInfo.tsx @@ -190,7 +190,7 @@ const DefendantInfo: FC = (props) => { onChange({ caseId: workingCase.id, defendantId: defendant.id, - nationalId: value, + nationalId: value || null, }) } onChange={(value) => @@ -198,7 +198,7 @@ const DefendantInfo: FC = (props) => { { caseId: workingCase.id, defendantId: defendant.id, - nationalId: value, + nationalId: value || null, }, setWorkingCase, ) diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index aaff6d5c197b..390946736f4a 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -262,10 +262,9 @@ export const isHearingArrangementsStepValidIC = ( export const isProcessingStepValidIndictments = ( workingCase: Case, ): boolean => { - const defendantsAreValid = () => - workingCase.defendants?.every((defendant) => { - return validate([[defendant.defendantPlea, ['empty']]]).isValid - }) + const defendantsAreValid = workingCase.defendants?.every( + (defendant) => validate([[defendant.defendantPlea, ['empty']]]).isValid, + ) const hasCivilClaimSelected = workingCase.hasCivilClaims !== null && @@ -275,9 +274,14 @@ export const isProcessingStepValidIndictments = ( ? workingCase.civilClaimants?.every( (civilClaimant) => civilClaimant.name && - (civilClaimant.noNationalId || - (civilClaimant.nationalId && - civilClaimant.nationalId.replace('-', '').length === 10)), + validate([ + [ + civilClaimant.nationalId, + civilClaimant.noNationalId + ? ['date-of-birth'] + : ['empty', 'national-id'], + ], + ]).isValid, ) : true @@ -286,7 +290,7 @@ export const isProcessingStepValidIndictments = ( workingCase.court && hasCivilClaimSelected && allCivilClaimantsAreValid && - defendantsAreValid(), + defendantsAreValid, ) }