From 110c9d2bed6cc9ed635f31835a4ff2f736523262 Mon Sep 17 00:00:00 2001 From: Philip Bardy <146740183+pbardy2000@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:19:32 +0000 Subject: [PATCH] feat(cb2-14743): remove recalls from test submission for non HGV/PSV/TRL tests (#1664) * feat(CB2-14743): add recalls banner * feat(CB2-14743): correct spelling mistakes * feat(CB2-14743): add an fix unit tests * feat(CB2-14743): remove recalls from non HGV/PSV/TRL to allow test submission * feat(CB2-14743): actually make request properly --------- Co-authored-by: Thomas Crawley --- src/app/resolvers/recalls/recalls.resolver.ts | 21 +++++++++++++------ .../test-records/test-records.reducer.ts | 7 +++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/app/resolvers/recalls/recalls.resolver.ts b/src/app/resolvers/recalls/recalls.resolver.ts index 413122e53..df0395943 100644 --- a/src/app/resolvers/recalls/recalls.resolver.ts +++ b/src/app/resolvers/recalls/recalls.resolver.ts @@ -3,6 +3,7 @@ import { ResolveFn } from '@angular/router'; import { RecallsSchema } from '@dvsa/cvs-type-definitions/types/v1/recalls'; import { Store, select } from '@ngrx/store'; import { Observable, catchError, filter, of, switchMap, tap } from 'rxjs'; +import { VehicleTypes } from '../../models/vehicle-tech-record.model'; import { HttpService } from '../../services/http/http.service'; import { techRecord } from '../../store/technical-records'; import { patchEditingTestResult } from '../../store/test-records'; @@ -14,11 +15,19 @@ export const recallsResolver: ResolveFn> = return store.pipe( select(techRecord), filter(Boolean), - switchMap((record) => - httpService.getRecalls(record.vin).pipe( - tap((recalls) => store.dispatch(patchEditingTestResult({ testResult: { recalls } }))), - catchError(() => of(undefined)) - ) - ) + switchMap((record) => { + if ( + record.techRecord_vehicleType === VehicleTypes.HGV || + record.techRecord_vehicleType === VehicleTypes.PSV || + record.techRecord_vehicleType === VehicleTypes.TRL + ) { + return httpService.getRecalls(record.vin).pipe( + tap((recalls) => store.dispatch(patchEditingTestResult({ testResult: { recalls } }))), + catchError(() => of(undefined)) + ); + } + + return of(undefined); + }) ); }; diff --git a/src/app/store/test-records/test-records.reducer.ts b/src/app/store/test-records/test-records.reducer.ts index 1479dde58..dc85c0abe 100644 --- a/src/app/store/test-records/test-records.reducer.ts +++ b/src/app/store/test-records/test-records.reducer.ts @@ -16,6 +16,7 @@ import { createFeatureSelector, createReducer, on } from '@ngrx/store'; import { FormNode } from '@services/dynamic-forms/dynamic-form.types'; import cloneDeep from 'lodash.clonedeep'; import merge from 'lodash.merge'; +import { VehicleTypes } from '../../models/vehicle-tech-record.model'; import { cancelEditingTestResult, cleanTestResult, @@ -187,6 +188,12 @@ function cleanTestResultPayload(testResult: TestResultModel | undefined) { return testResult; } + // Remove recalls from non HGV/PSV/TRL tests + const vehicleType = testResult.vehicleType; + if (!(vehicleType === VehicleTypes.HGV || vehicleType === VehicleTypes.PSV || vehicleType === VehicleTypes.TRL)) { + delete testResult.recalls; + } + const testTypes = testResult.testTypes.map((testType, index) => { // Remove empty requiredStandards from pass/prs non-voluntary IVA/MVSA tests if (index === 0) {