Skip to content

Commit

Permalink
Merge branch 'feat/cb2-14457' into feature/VTMDEV-2
Browse files Browse the repository at this point in the history
  • Loading branch information
pbardy2000 committed Nov 19, 2024
2 parents fa8fb74 + ff87e71 commit e365baa
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ng-container *ngIf="control?.invalid && control?.touched && control?.errors">
<p class="govuk-error-message" [id]="elementId">
<span class="govuk-visually-hidden">Error:</span>
<span class="govuk-visually-hidden">Error: </span>
<span>{{ (control.errors | keyvalue)?.[0]?.value }}</span>
</p>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -81,7 +80,7 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy {
),
]
),
techRecord_adrDetails_bodyDeclaration_type: this.fb.control<string | null>(null, []),
techRecord_adrDetails_bodyDeclaration_type: this.fb.control<string | undefined>(undefined, []),
techRecord_adrDetails_compatibilityGroupJ: this.fb.control<boolean | null>(null, [
this.adrValidators.requiredWithExplosives('Compatibility group J is required with Permitted dangerous goods'),
]),
Expand All @@ -100,12 +99,13 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy {
]),
techRecord_adrDetails_tank_tankDetails_yearOfManufacture: this.fb.control<number | null>(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'),
]),
techRecord_adrDetails_tank_tankDetails_tankManufacturerSerialNo: this.fb.control<string | null>(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<string | null>(null, [
this.adrValidators.requiredWithTankOrBattery('Tank type approval number is required with ADR body type'),
Expand Down Expand Up @@ -152,7 +152,7 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy {
]),

// Tank Details > Tank Inspections
techRecord_adrDetails_tank_tankDetails_tc2Details_tc2Type: this.fb.control<string | null>(TC2Types.INITIAL),
techRecord_adrDetails_tank_tankDetails_tc2Details_tc2Type: this.fb.control<string | null>('initial'),
techRecord_adrDetails_tank_tankDetails_tc2Details_tc2IntermediateApprovalNo: this.fb.control<string | null>(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'),
Expand All @@ -169,22 +169,22 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy {

// Battery List
techRecord_adrDetails_listStatementApplicable: this.fb.control<string | null>(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<string | null>(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
techRecord_adrDetails_brakeDeclarationsSeen: this.fb.control<boolean>(false),
techRecord_adrDetails_brakeDeclarationIssuer: this.fb.control<string | null>(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<boolean>(false),
techRecord_adrDetails_weight: this.fb.control<number | null>(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'),
]),

Expand Down Expand Up @@ -296,7 +296,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 }) => {
Expand Down
12 changes: 9 additions & 3 deletions src/app/forms/validators/adr-validators.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/app/forms/validators/common-validators.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down
20 changes: 20 additions & 0 deletions src/app/services/technical-record/technical-record.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ 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;
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 }));
}

Expand Down

0 comments on commit e365baa

Please sign in to comment.