From bc4b6372f08686e1a53b1c72dcb5b6e9193c7f1a Mon Sep 17 00:00:00 2001 From: juni-haukur <158475136+juni-haukur@users.noreply.github.com> Date: Mon, 24 Jun 2024 08:41:00 +0000 Subject: [PATCH] fix(driving-license): Prevent temp license holders from applying for BE license (#15278) * prevent temp license holders from applying for BE license * update be license endpoint * update text --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/lib/drivingLicense.service.ts | 8 ++++-- .../src/lib/drivingLicense.type.ts | 7 ++++++ .../driving-license-submission.service.ts | 13 +++++++++- .../prerequisites/sectionApplicationFor.ts | 18 +++++++++---- .../driving-license/src/lib/messages.ts | 2 +- .../driving-license/src/lib/types.ts | 1 + .../src/lib/drivingLicenseApi.service.ts | 6 +++++ .../driving-license/src/v5/clientConfig.json | 25 +++++++++++++++++++ 8 files changed, 71 insertions(+), 9 deletions(-) diff --git a/libs/api/domains/driving-license/src/lib/drivingLicense.service.ts b/libs/api/domains/driving-license/src/lib/drivingLicense.service.ts index d031499a9dfa..97093ce252d7 100644 --- a/libs/api/domains/driving-license/src/lib/drivingLicense.service.ts +++ b/libs/api/domains/driving-license/src/lib/drivingLicense.service.ts @@ -13,6 +13,7 @@ import { NewTemporaryDrivingLicenseInput, ApplicationEligibilityRequirement, QualitySignatureResult, + NewBEDrivingLicenseInput, } from './drivingLicense.type' import { CanApplyErrorCodeBFull, @@ -459,12 +460,15 @@ export class DrivingLicenseService { async applyForBELicense( nationalId: User['nationalId'], auth: User['authorization'], - jurisdiction: number, + input: NewBEDrivingLicenseInput, ): Promise { const response = await this.drivingLicenseApi.postApplyForBELicense({ nationalIdApplicant: nationalId, token: auth, - jurisdictionId: jurisdiction, + jurisdictionId: input.jurisdiction, + instructorSSN: input.instructorSSN, + email: input.studentEmail, + phoneNumber: input.primaryPhoneNumber, }) return { diff --git a/libs/api/domains/driving-license/src/lib/drivingLicense.type.ts b/libs/api/domains/driving-license/src/lib/drivingLicense.type.ts index b97485160eba..fdcda87b214e 100644 --- a/libs/api/domains/driving-license/src/lib/drivingLicense.type.ts +++ b/libs/api/domains/driving-license/src/lib/drivingLicense.type.ts @@ -25,6 +25,13 @@ export interface NewTemporaryDrivingLicenseInput { phone: string } +export interface NewBEDrivingLicenseInput { + jurisdiction: number + instructorSSN: string + primaryPhoneNumber: string + studentEmail: string +} + export interface NewDrivingLicenseResult { success: boolean errorMessage: string | null diff --git a/libs/application/template-api-modules/src/lib/modules/templates/driving-license-submission/driving-license-submission.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/driving-license-submission/driving-license-submission.service.ts index 70568fb2060d..d4cde5464157 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/driving-license-submission/driving-license-submission.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/driving-license-submission/driving-license-submission.service.ts @@ -197,10 +197,21 @@ export class DrivingLicenseSubmissionService extends BaseTemplateApiService { }, ) } else if (applicationFor === 'BE') { + const instructorSSN = getValueViaPath( + answers, + 'drivingInstructor', + ) + const email = getValueViaPath(answers, 'email') + const phone = getValueViaPath(answers, 'phone') return this.drivingLicenseService.applyForBELicense( nationalId, auth.authorization, - jurisdictionId as number, + { + jurisdiction: jurisdictionId as number, + instructorSSN: instructorSSN ?? '', + primaryPhoneNumber: phone ?? '', + studentEmail: email ?? '', + }, ) } diff --git a/libs/application/templates/driving-license/src/forms/prerequisites/sectionApplicationFor.ts b/libs/application/templates/driving-license/src/forms/prerequisites/sectionApplicationFor.ts index 3fb187887287..1c4686790468 100644 --- a/libs/application/templates/driving-license/src/forms/prerequisites/sectionApplicationFor.ts +++ b/libs/application/templates/driving-license/src/forms/prerequisites/sectionApplicationFor.ts @@ -47,11 +47,16 @@ export const sectionApplicationFor = (allowBELicense = false) => if (fakeData?.useFakeData === 'yes') { currentLicense = fakeData.currentLicense ?? null categories = - fakeData.currentLicense === 'full' - ? [{ nr: 'B' }] + fakeData.currentLicense === 'temp' + ? [{ nr: 'B', validToCode: 8 }] + : fakeData.currentLicense === 'full' + ? [{ nr: 'B', validToCode: 9 }] : fakeData.currentLicense === 'BE' - ? [{ nr: 'B' }, { nr: 'BE' }] - : null + ? [ + { nr: 'B', validToCode: 9 }, + { nr: 'BE', validToCode: 9 }, + ] + : [] } let options = [ @@ -80,7 +85,10 @@ export const sectionApplicationFor = (allowBELicense = false) => !currentLicense || age < 18 || categories?.some((c) => c.nr.toUpperCase() === 'BE') || - !categories?.some((c) => c.nr.toUpperCase() === 'B'), + // validToCode === 8 is temporary license and should not be applicable for BE + !categories?.some( + (c) => c.nr.toUpperCase() === 'B' && c.validToCode !== 8, + ), }) } diff --git a/libs/application/templates/driving-license/src/lib/messages.ts b/libs/application/templates/driving-license/src/lib/messages.ts index 55a9f875b454..724414042c3f 100644 --- a/libs/application/templates/driving-license/src/lib/messages.ts +++ b/libs/application/templates/driving-license/src/lib/messages.ts @@ -728,7 +728,7 @@ export const m = defineMessages({ }, applicationForBELicenseTitle: { id: 'dl.application:applicationForBELicenseTitle', - defaultMessage: 'Kerruréttindi BE', + defaultMessage: 'Eftirvagn BE', description: 'Option title for selecting to apply for trailer license', }, applicationForBELicenseDescription: { diff --git a/libs/application/templates/driving-license/src/lib/types.ts b/libs/application/templates/driving-license/src/lib/types.ts index 25009cc9ebba..9d6a0822279e 100644 --- a/libs/application/templates/driving-license/src/lib/types.ts +++ b/libs/application/templates/driving-license/src/lib/types.ts @@ -10,6 +10,7 @@ export type ConditionFn = (answer: FormValue) => boolean export type DrivingLicenseCategory = { nr: string + validToCode: number } export type DrivingLicense = { diff --git a/libs/clients/driving-license/src/lib/drivingLicenseApi.service.ts b/libs/clients/driving-license/src/lib/drivingLicenseApi.service.ts index 7aeb2e1868fa..7b1c2f9c3273 100644 --- a/libs/clients/driving-license/src/lib/drivingLicenseApi.service.ts +++ b/libs/clients/driving-license/src/lib/drivingLicenseApi.service.ts @@ -480,6 +480,9 @@ export class DrivingLicenseApi { nationalIdApplicant: string token: string jurisdictionId: number + instructorSSN: string + phoneNumber: string + email: string }): Promise { const response = await this.applicationV5.apiApplicationsV5ApplyforBePost({ apiVersion: v5.DRIVING_LICENSE_API_VERSION_V5, @@ -488,6 +491,9 @@ export class DrivingLicenseApi { postApplicationForBEModel: { districtId: params.jurisdictionId, userId: v5.DRIVING_LICENSE_API_USER_ID, + instructorSSN: params.instructorSSN, + primaryPhoneNumber: params.phoneNumber, + studentEmail: params.email, }, }) diff --git a/libs/clients/driving-license/src/v5/clientConfig.json b/libs/clients/driving-license/src/v5/clientConfig.json index 1b948f3c0d97..51844f36485a 100644 --- a/libs/clients/driving-license/src/v5/clientConfig.json +++ b/libs/clients/driving-license/src/v5/clientConfig.json @@ -2987,6 +2987,11 @@ "type": "string", "description": "Origin of creation", "nullable": true + }, + "districtId": { + "type": "integer", + "description": "District id", + "format": "int32" } }, "additionalProperties": false, @@ -3406,6 +3411,21 @@ "description": "UserId", "nullable": true }, + "instructorSSN": { + "type": "string", + "description": "Driving instructor social security number", + "nullable": true + }, + "primaryPhoneNumber": { + "type": "string", + "description": "Primary phone number", + "nullable": true + }, + "studentEmail": { + "type": "string", + "description": "Student email", + "nullable": true + }, "districtId": { "type": "integer", "description": "Ordering district", @@ -3850,6 +3870,11 @@ "type": "string", "description": "Origin of creation", "nullable": true + }, + "districtId": { + "type": "integer", + "description": "District id", + "format": "int32" } }, "additionalProperties": false,