Skip to content

Commit

Permalink
Merge branch 'develop' into feat/CB2-14459
Browse files Browse the repository at this point in the history
  • Loading branch information
pbardy2000 committed Dec 11, 2024
2 parents 8e00d3c + 110c9d2 commit 6e17ade
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/app/resolvers/recalls/recalls.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -14,11 +15,19 @@ export const recallsResolver: ResolveFn<Observable<RecallsSchema | undefined>> =
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);
})
);
};
7 changes: 7 additions & 0 deletions src/app/store/test-records/test-records.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6e17ade

Please sign in to comment.