forked from Yara724/api
fix(licence): validate driving licence IDs and preserve verified captions
This commit is contained in:
@@ -13,6 +13,8 @@ import {
|
||||
import { ExternalExceptionFilter } from "@nestjs/core/exceptions/external-exception-filter";
|
||||
import { Types } from "mongoose";
|
||||
import { ClientService } from "src/client/client.service";
|
||||
import { LookupsService } from "src/lookups/lookups.service";
|
||||
import { selectedDrivingLicenceType } from "src/lookups/driving-licence-types";
|
||||
import { AddPlateDto } from "src/profile/dto/user/AddPlateDto";
|
||||
import { VehicleRegistrationState } from "src/common/dto/inquiry-participants.dto";
|
||||
import {
|
||||
@@ -372,6 +374,19 @@ export class RequestManagementService {
|
||||
return normalizeInquirySubmission(type, input);
|
||||
}
|
||||
|
||||
private async validateDrivingLicenceType(
|
||||
submission: NormalizedInquirySubmission<Record<string, any>>,
|
||||
): Promise<void> {
|
||||
if (submission.driver.hasDrivingLicense !== true) return;
|
||||
const selected = selectedDrivingLicenceType(
|
||||
submission.driver.licenseType,
|
||||
await this.lookupsService.getDrivingLicenceTypes(),
|
||||
);
|
||||
// Store the provider ID unchanged and a server-verified caption for display.
|
||||
submission.driver.licenseTypeLabel = selected.Caption;
|
||||
submission.dto.licenseTypeLabel = selected.Caption;
|
||||
}
|
||||
|
||||
private applyInquiryParticipantsToParty(
|
||||
party: any,
|
||||
submission: NormalizedInquirySubmission<Record<string, any>>,
|
||||
@@ -1163,6 +1178,7 @@ export class RequestManagementService {
|
||||
private readonly fanavaranLocationService: FanavaranLocationService,
|
||||
private readonly fileMakerDbService: FileMakerDbService,
|
||||
private readonly fileReviewerDbService: FileReviewerDbService,
|
||||
private readonly lookupsService: LookupsService,
|
||||
) {}
|
||||
|
||||
async assertFileReviewerBranchAccess(
|
||||
@@ -1857,6 +1873,7 @@ export class RequestManagementService {
|
||||
req.type,
|
||||
body,
|
||||
);
|
||||
await this.validateDrivingLicenceType(inquirySubmission);
|
||||
body = inquirySubmission.dto as unknown as AddPlateDto;
|
||||
this.applyInquiryParticipantsToParty(party, inquirySubmission);
|
||||
|
||||
@@ -2304,6 +2321,7 @@ export class RequestManagementService {
|
||||
req.type,
|
||||
body,
|
||||
);
|
||||
await this.validateDrivingLicenceType(inquirySubmission);
|
||||
body = inquirySubmission.dto as unknown as InitialFormVinDto;
|
||||
const subjects = resolveInquirySubjects(inquirySubmission);
|
||||
this.applyInquiryParticipantsToParty(party, inquirySubmission);
|
||||
@@ -3822,6 +3840,7 @@ export class RequestManagementService {
|
||||
request.type as BlameRequestType,
|
||||
body,
|
||||
);
|
||||
await this.validateDrivingLicenceType(inquirySubmission);
|
||||
body = inquirySubmission.dto as unknown as AddPlateDto;
|
||||
|
||||
if (!isFirstParty) {
|
||||
@@ -7207,6 +7226,7 @@ export class RequestManagementService {
|
||||
req.type,
|
||||
formData.firstPartyPlate,
|
||||
);
|
||||
await this.validateDrivingLicenceType(inquirySubmission);
|
||||
this.recordInquiryParticipantContext(
|
||||
req,
|
||||
PartyRole.FIRST,
|
||||
@@ -7538,6 +7558,7 @@ export class RequestManagementService {
|
||||
req.type,
|
||||
plateDto,
|
||||
);
|
||||
await this.validateDrivingLicenceType(inquirySubmission);
|
||||
this.recordInquiryParticipantContext(req, role, inquirySubmission);
|
||||
const existingPartyIndex = this.getPartyIndex(req, role);
|
||||
if (existingPartyIndex !== -1) {
|
||||
@@ -8324,6 +8345,7 @@ export class RequestManagementService {
|
||||
BlameRequestType.THIRD_PARTY,
|
||||
formData.firstPartyPlate,
|
||||
);
|
||||
await this.validateDrivingLicenceType(firstInquirySubmission);
|
||||
const firstPartyPlate = firstInquirySubmission.dto;
|
||||
let firstPolicyInquiry: any;
|
||||
try {
|
||||
@@ -8464,6 +8486,7 @@ export class RequestManagementService {
|
||||
BlameRequestType.THIRD_PARTY,
|
||||
formData.secondParty.plate,
|
||||
);
|
||||
await this.validateDrivingLicenceType(secondInquirySubmission);
|
||||
let secondPolicyInquiry: any;
|
||||
try {
|
||||
const secondPartyPlate = secondInquirySubmission.dto;
|
||||
@@ -8819,6 +8842,7 @@ export class RequestManagementService {
|
||||
BlameRequestType.CAR_BODY,
|
||||
formData.firstPartyPlate,
|
||||
);
|
||||
await this.validateDrivingLicenceType(firstInquirySubmission);
|
||||
const firstPartyPlate = firstInquirySubmission.dto;
|
||||
let thirdPartyPolicyInquiry: any;
|
||||
let carBodyInquiry: any;
|
||||
@@ -10071,6 +10095,7 @@ export class RequestManagementService {
|
||||
req.type,
|
||||
partyData,
|
||||
);
|
||||
await this.validateDrivingLicenceType(inquirySubmission);
|
||||
partyData = inquirySubmission.dto as RunInquiriesV3Dto;
|
||||
const subjects = resolveInquirySubjects(inquirySubmission);
|
||||
this.applyInquiryParticipantsToParty(party, inquirySubmission);
|
||||
@@ -10224,6 +10249,7 @@ export class RequestManagementService {
|
||||
party.person.driverLicenseDate = (partyData as any).driverLicenseDate;
|
||||
if ((partyData as any).licenseType)
|
||||
(party.person as any).licenseType = (partyData as any).licenseType;
|
||||
(party.person as any).licenseTypeLabel = (partyData as any).licenseTypeLabel;
|
||||
|
||||
if (!party.vehicle) party.vehicle = {} as any;
|
||||
party.vehicle.plateId = this.plateToPlateIdString(partyData.plate);
|
||||
@@ -11001,6 +11027,7 @@ export class RequestManagementService {
|
||||
req.type,
|
||||
partyData,
|
||||
);
|
||||
await this.validateDrivingLicenceType(inquirySubmission);
|
||||
partyData = inquirySubmission.dto as RunInquiriesVinV3Dto;
|
||||
const subjects = resolveInquirySubjects(inquirySubmission);
|
||||
this.applyInquiryParticipantsToParty(party, inquirySubmission);
|
||||
@@ -11134,6 +11161,7 @@ export class RequestManagementService {
|
||||
party.person.driverLicenseDate = (partyData as any).driverLicenseDate;
|
||||
if ((partyData as any).licenseType)
|
||||
(party.person as any).licenseType = (partyData as any).licenseType;
|
||||
(party.person as any).licenseTypeLabel = (partyData as any).licenseTypeLabel;
|
||||
|
||||
if (!party.vehicle) party.vehicle = {} as any;
|
||||
// Derive plateId from the plate parts returned by the VIN inquiry.
|
||||
@@ -12972,6 +13000,7 @@ export class RequestManagementService {
|
||||
driverBirthday: p.person?.driverBirthday,
|
||||
clientId: p.person?.clientId ? String(p.person.clientId) : undefined,
|
||||
licenseType: p.person?.licenseType ?? undefined,
|
||||
licenseTypeLabel: p.person?.licenseTypeLabel ?? undefined,
|
||||
},
|
||||
insurance: p.insurance
|
||||
? {
|
||||
@@ -13318,6 +13347,7 @@ export class RequestManagementService {
|
||||
userId: p.person?.userId ? String(p.person.userId) : undefined,
|
||||
clientId: p.person?.clientId ? String(p.person.clientId) : undefined,
|
||||
licenseType: p.person?.licenseType ?? undefined,
|
||||
licenseTypeLabel: p.person?.licenseTypeLabel ?? undefined,
|
||||
},
|
||||
insurance: p.insurance
|
||||
? {
|
||||
@@ -13561,6 +13591,7 @@ export class RequestManagementService {
|
||||
userId: p.person?.userId ? String(p.person.userId) : undefined,
|
||||
clientId: p.person?.clientId ? String(p.person.clientId) : undefined,
|
||||
licenseType: p.person?.licenseType ?? undefined,
|
||||
licenseTypeLabel: p.person?.licenseTypeLabel ?? undefined,
|
||||
},
|
||||
insurance: p.insurance
|
||||
? {
|
||||
|
||||
Reference in New Issue
Block a user