From 2e906a7b35c507f29f026d75d1a750760204b4bf Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Mon, 18 Nov 2024 15:28:24 +0000 Subject: [PATCH 1/8] feat(cb2-14457): fix battery list applicable validation --- .../adr-section-edit/adr-section-edit.component.ts | 5 ++--- src/app/forms/validators/adr-validators.service.ts | 12 +++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts index d3a53627a..e6221bbde 100644 --- a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts +++ b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts @@ -15,7 +15,6 @@ import { TechRecordType } from '@dvsa/cvs-type-definitions/types/v3/tech-record/ import { getOptionsFromEnum } from '@forms/utils/enum-map'; import { AdrValidatorsService } from '@forms/validators/adr-validators.service'; import { CommonValidatorsService } from '@forms/validators/common-validators.service'; -import { TC2Types } from '@models/adr.enum'; import { Store } from '@ngrx/store'; import { AdrService } from '@services/adr/adr.service'; import { TechnicalRecordService } from '@services/technical-record/technical-record.service'; @@ -152,7 +151,7 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy { ]), // Tank Details > Tank Inspections - techRecord_adrDetails_tank_tankDetails_tc2Details_tc2Type: this.fb.control(TC2Types.INITIAL), + techRecord_adrDetails_tank_tankDetails_tc2Details_tc2Type: this.fb.control('initial'), techRecord_adrDetails_tank_tankDetails_tc2Details_tc2IntermediateApprovalNo: this.fb.control(null, [ this.adrValidators.requiredWithTankOrBattery('TC2: Certificate Number is required with ADR body type'), this.commonValidators.maxLength(70, 'TC2: Certificate Number must be less than or equal to 70 characters'), @@ -169,7 +168,7 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy { // Battery List techRecord_adrDetails_listStatementApplicable: this.fb.control(null, [ - this.adrValidators.requiredWithBattery('Battery List Applicable is required with ADR body type'), + this.adrValidators.requiredWithBattery('Battery List Applicable is required with ADR body type', true), ]), techRecord_adrDetails_batteryListNumber: this.fb.control(null, [ this.adrValidators.requiredWithBatteryListApplicable('Reference Number is required with Battery List Applicable'), diff --git a/src/app/forms/validators/adr-validators.service.ts b/src/app/forms/validators/adr-validators.service.ts index f6d82050e..511746124 100644 --- a/src/app/forms/validators/adr-validators.service.ts +++ b/src/app/forms/validators/adr-validators.service.ts @@ -34,10 +34,16 @@ export class AdrValidatorsService { }; } - requiredWithBattery(message: string): ValidatorFn { + requiredWithBattery(message: string, allowFalse = false): ValidatorFn { return (control) => { - if (control.parent && !control.value && this.adrService.canDisplayBatterySection(control.parent.value)) { - return { required: message }; + if (control.parent && this.adrService.canDisplayBatterySection(control.parent.value)) { + if (allowFalse && control.value === false) { + return null; + } + + if (!control.value) { + return { required: message }; + } } return null; From f338e5eeece563d49ec143f519346c0ffc8ee547 Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:10:13 +0000 Subject: [PATCH 2/8] feat(cb2-14457): test --- .../adr-section-edit/adr-section-edit.component.ts | 4 ++-- .../technical-record/technical-record.service.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts index e6221bbde..5ada68b27 100644 --- a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts +++ b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts @@ -80,7 +80,7 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy { ), ] ), - techRecord_adrDetails_bodyDeclaration_type: this.fb.control(null, []), + techRecord_adrDetails_bodyDeclaration_type: this.fb.control(undefined, []), techRecord_adrDetails_compatibilityGroupJ: this.fb.control(null, [ this.adrValidators.requiredWithExplosives('Compatibility group J is required with Permitted dangerous goods'), ]), @@ -295,7 +295,7 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy { return good !== ADRDangerousGood.EXPLOSIVES_TYPE_2 && good !== ADRDangerousGood.EXPLOSIVES_TYPE_3; }), techRecord_adrDetails_compatibilityGroupJ: null, - techRecord_adrDetails_bodyDeclaration_type: null, + techRecord_adrDetails_bodyDeclaration_type: undefined, }); this.permittedDangerousGoodsOptions = options.filter(({ value }) => { diff --git a/src/app/services/technical-record/technical-record.service.ts b/src/app/services/technical-record/technical-record.service.ts index 1b73c7a14..53f661aae 100644 --- a/src/app/services/technical-record/technical-record.service.ts +++ b/src/app/services/technical-record/technical-record.service.ts @@ -130,6 +130,16 @@ export class TechnicalRecordService { record.techRecord_noOfAxles = record.techRecord_axles && record.techRecord_axles.length > 0 ? record.techRecord_axles?.length : null; } + + // @TODO - replace this hacky solution with a better one + if ( + record.techRecord_vehicleType === 'hgv' || + record.techRecord_vehicleType === 'trl' || + record.techRecord_vehicleType === 'lgv' + ) { + record.techRecord_adrDetails_bodyDeclaration_type = undefined; + } + this.store.dispatch(updateEditingTechRecord({ vehicleTechRecord: record })); } From 8421767c582bed9b3bd11e3c4443fb74c3dd4742 Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:00:50 +0000 Subject: [PATCH 3/8] feat(cb2-14457): fix error messages for automation pack --- .../components/control-errors/control-errors.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/forms/components/control-errors/control-errors.component.html b/src/app/forms/components/control-errors/control-errors.component.html index 338b58593..44a7aa57f 100644 --- a/src/app/forms/components/control-errors/control-errors.component.html +++ b/src/app/forms/components/control-errors/control-errors.component.html @@ -1,6 +1,6 @@

- Error: + Error: {{ (control.errors | keyvalue)?.[0]?.value }}

From b4314181c97395b21f0343fc9ad0d837e067ac4e Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:37:26 +0000 Subject: [PATCH 4/8] feat(cb2-14457): fix ADR specific issues --- .../adr-section-edit/adr-section-edit.component.ts | 5 +++-- src/app/forms/validators/common-validators.service.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts index 5ada68b27..0c8678f93 100644 --- a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts +++ b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts @@ -99,6 +99,7 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy { ]), techRecord_adrDetails_tank_tankDetails_yearOfManufacture: this.fb.control(null, [ this.adrValidators.requiredWithTankOrBattery('Tank Year of manufacture is required with ADR body type'), + this.commonValidators.pastOrCurrentYear('Tank Year of manufacture must be the current or a past year'), this.commonValidators.min(1000, 'Tank Year of manufacture must be greater than or equal to 1000'), this.commonValidators.max(9999, 'Tank Year of manufacture must be less than or equal to 9999'), ]), @@ -171,8 +172,8 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy { this.adrValidators.requiredWithBattery('Battery List Applicable is required with ADR body type', true), ]), techRecord_adrDetails_batteryListNumber: this.fb.control(null, [ - this.adrValidators.requiredWithBatteryListApplicable('Reference Number is required with Battery List Applicable'), - this.commonValidators.maxLength(8, 'Reference Number must be less than or equal to 8 characters'), + this.adrValidators.requiredWithBatteryListApplicable('Reference number is required with Battery List Applicable'), + this.commonValidators.maxLength(8, 'Reference number must be less than or equal to 8 characters'), ]), // Brake declaration diff --git a/src/app/forms/validators/common-validators.service.ts b/src/app/forms/validators/common-validators.service.ts index 89c4a96f9..715bc9443 100644 --- a/src/app/forms/validators/common-validators.service.ts +++ b/src/app/forms/validators/common-validators.service.ts @@ -54,6 +54,16 @@ export class CommonValidatorsService { }; } + pastOrCurrentYear(message: string): ValidatorFn { + return (control) => { + if (control.value && +control.value > new Date().getFullYear()) { + return { pastOrCurrentYear: message }; + } + + return null; + }; + } + invalidDate(message: string): ValidatorFn { return (control) => { if (control.value && Number.isNaN(Date.parse(control.value))) { From 295acc127d73e8c65bb4664b7c1fe2c46feb049f Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Tue, 19 Nov 2024 08:40:11 +0000 Subject: [PATCH 5/8] feat(cb2-14457): correct max length validation --- .../adr-section/adr-section-edit/adr-section-edit.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts index 0c8678f93..340ca0ed1 100644 --- a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts +++ b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts @@ -105,7 +105,7 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy { ]), techRecord_adrDetails_tank_tankDetails_tankManufacturerSerialNo: this.fb.control(null, [ this.adrValidators.requiredWithTankOrBattery('Manufacturer serial number is required with ADR body type'), - this.commonValidators.maxLength(70, 'Manufacturer serial number must be less than or equal to 70 characters'), + this.commonValidators.maxLength(50, 'Manufacturer serial number must be less than or equal to 50 characters'), ]), techRecord_adrDetails_tank_tankDetails_tankTypeAppNo: this.fb.control(null, [ this.adrValidators.requiredWithTankOrBattery('Tank type approval number is required with ADR body type'), From 9161ab4c6178c74f5aec737d634e91beca1c8de6 Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:19:38 +0000 Subject: [PATCH 6/8] feat(cb2-14457): correct more messages --- .../adr-section-edit/adr-section-edit.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts index 340ca0ed1..efacc4a3d 100644 --- a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts +++ b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts @@ -179,12 +179,12 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy { // Brake declaration techRecord_adrDetails_brakeDeclarationsSeen: this.fb.control(false), techRecord_adrDetails_brakeDeclarationIssuer: this.fb.control(null, [ - this.commonValidators.maxLength(500, 'Issuer must be lest than or equal to 500 characters'), + this.commonValidators.maxLength(500, 'Issuer must be less than or equal to 500 characters'), ]), techRecord_adrDetails_brakeEndurance: this.fb.control(false), techRecord_adrDetails_weight: this.fb.control(null, [ this.commonValidators.max(99999999, 'Weight (tonnes) must be less than or equal to 99999999'), - this.adrValidators.requiredWithBrakeEndurance('Weight (tonnes) is required with Brake Endurance'), + this.adrValidators.requiredWithBrakeEndurance('Weight (tonnes) is required'), this.commonValidators.pattern('^\\d*(\\.\\d{0,2})?$', 'Weight (tonnes) must be a number'), ]), From d528b9827250c68f5b883073e0137aba5bb51f64 Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:41:40 +0000 Subject: [PATCH 7/8] feat(cb2-14457): fix batch plating --- .../technical-record/technical-record.service.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/app/services/technical-record/technical-record.service.ts b/src/app/services/technical-record/technical-record.service.ts index 53f661aae..ec575bfed 100644 --- a/src/app/services/technical-record/technical-record.service.ts +++ b/src/app/services/technical-record/technical-record.service.ts @@ -138,6 +138,16 @@ export class TechnicalRecordService { record.techRecord_vehicleType === 'lgv' ) { record.techRecord_adrDetails_bodyDeclaration_type = undefined; + if (Array.isArray(record.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo)) { + // remove all nulls from array + record.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo = + record.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo.filter((unNo) => !!unNo); + + // if array is empty, set to null + if (!record.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo.length) { + record.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo = null; + } + } } this.store.dispatch(updateEditingTechRecord({ vehicleTechRecord: record })); From ff87e715face48874ff5f8d2f7fdb678cac6a4bb Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:22:30 +0000 Subject: [PATCH 8/8] feat(cb2-14457): change wording --- .../components/character-count/character-count.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/forms/components/character-count/character-count.component.html b/src/app/forms/components/character-count/character-count.component.html index b7a6a1741..a9e292a2a 100644 --- a/src/app/forms/components/character-count/character-count.component.html +++ b/src/app/forms/components/character-count/character-count.component.html @@ -6,5 +6,5 @@ class="govuk-hint govuk-character-count__message govuk-character-count__status govuk-error-message" *ngIf="(control()?.value?.length ?? 0) > limit()" > - You have {{ (control()?.value?.length ?? limit()) - limit() }} too many + You have {{ (control()?.value?.length ?? limit()) - limit() }} characters too many