forked from Yara724/api
add 4 new fields for expert approval
This commit is contained in:
@@ -4815,11 +4815,16 @@ export class ClaimRequestManagementService {
|
||||
parseFanavaranId(apiVehicle?.BuiltYear) ?? builtYearFromInquiry;
|
||||
|
||||
const carType = input.claimCase?.vehicle?.carType as string | undefined;
|
||||
let vehicleKindId = this.firstPositiveFanavaranId(apiVehicle?.VehicleKindId);
|
||||
let vehicleKindSource: "vehicle-inquiry" | "car-type-lookup" | null =
|
||||
parseFanavaranId(apiVehicle?.VehicleKindId) != null
|
||||
? "vehicle-inquiry"
|
||||
: null;
|
||||
const approvedVehicleKindId = this.firstPositiveFanavaranId(
|
||||
input.claimCase?.fanavaranVehicleReview?.vehicleKind?.id,
|
||||
);
|
||||
let vehicleKindId = approvedVehicleKindId ?? this.firstPositiveFanavaranId(apiVehicle?.VehicleKindId);
|
||||
let vehicleKindSource: "expert-review" | "vehicle-inquiry" | "car-type-lookup" | null =
|
||||
approvedVehicleKindId != null
|
||||
? "expert-review"
|
||||
: parseFanavaranId(apiVehicle?.VehicleKindId) != null
|
||||
? "vehicle-inquiry"
|
||||
: null;
|
||||
if (vehicleKindId == null) {
|
||||
vehicleKindId = await this.resolveVehicleKindId(
|
||||
input.clientKey,
|
||||
@@ -4944,9 +4949,12 @@ export class ClaimRequestManagementService {
|
||||
input.clientKey,
|
||||
);
|
||||
|
||||
let accidentVehicleUsedId: number | null = null;
|
||||
let usedSource: "vin-inquiry" | "policy-vehicle" | "vehicle-inquiry" | null =
|
||||
null;
|
||||
const approvedVehicleUseTypeId = this.firstPositiveFanavaranId(
|
||||
input.claimCase?.fanavaranVehicleReview?.vehicleUseType?.id,
|
||||
);
|
||||
let accidentVehicleUsedId: number | null = approvedVehicleUseTypeId;
|
||||
let usedSource: "expert-review" | "vin-inquiry" | "policy-vehicle" | "vehicle-inquiry" | null =
|
||||
approvedVehicleUseTypeId != null ? "expert-review" : null;
|
||||
if (accidentVehicleUsedId == null && apiVehicle) {
|
||||
const fromDamagedVehicle =
|
||||
await this.resolveAccidentVehicleUsedFromVehicleRecord(
|
||||
@@ -6372,7 +6380,7 @@ export class ClaimRequestManagementService {
|
||||
cachedUsedSource === "policy-vehicle");
|
||||
|
||||
delete payload.AccidentVehicleUsedId;
|
||||
let usedSource: "vin-inquiry" | "policy-vehicle" | null = null;
|
||||
let usedSource: "expert-review" | "vin-inquiry" | "policy-vehicle" | null = null;
|
||||
if (canReuseApiUsedId) {
|
||||
payload.AccidentVehicleUsedId = Number(cachedUsedId);
|
||||
usedSource = cachedUsedSource;
|
||||
@@ -6395,6 +6403,14 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
}
|
||||
|
||||
const approvedUseTypeId = Number(
|
||||
(claimCase as any)?.fanavaranVehicleReview?.vehicleUseType?.id,
|
||||
);
|
||||
if (Number.isInteger(approvedUseTypeId) && approvedUseTypeId > 0) {
|
||||
payload.AccidentVehicleUsedId = approvedUseTypeId;
|
||||
usedSource = "expert-review";
|
||||
}
|
||||
|
||||
if (parseFanavaranId(payload.AccidentVehicleUsedId) == null) {
|
||||
payload.AccidentVehicleUsedId =
|
||||
profile.defaults.AccidentVehicleUsedId;
|
||||
@@ -6497,6 +6513,7 @@ export class ClaimRequestManagementService {
|
||||
FanavaranAuditSource.SUBMIT,
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof HttpException) throw error;
|
||||
this.logger.error(
|
||||
`[Fanavaran ${clientKey} V2] Error submitting to Fanavaran`,
|
||||
error,
|
||||
@@ -6594,6 +6611,7 @@ export class ClaimRequestManagementService {
|
||||
bodyOverride,
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof HttpException) throw error;
|
||||
this.logger.error(
|
||||
`[Fanavaran ${clientKey} V2] Error submitting damage case to Fanavaran`,
|
||||
error,
|
||||
@@ -6790,6 +6808,7 @@ export class ClaimRequestManagementService {
|
||||
|
||||
const profile = getFanavaranClientProfile(clientKey);
|
||||
let claimCase = await this.claimCaseDbService.findById(claimCaseId);
|
||||
if (claimCase) this.assertFanavaranVehicleReviewApproved(claimCase);
|
||||
if (!claimCase?.claimId) {
|
||||
try {
|
||||
await this.ensureFanavaranBaseClaim(
|
||||
@@ -7628,6 +7647,8 @@ export class ClaimRequestManagementService {
|
||||
auditSource: FanavaranAuditSource,
|
||||
): Promise<any> {
|
||||
let claimCase = await this.claimCaseDbService.findById(claimCaseId);
|
||||
if (!claimCase) throw new NotFoundException("Claim case not found");
|
||||
this.assertFanavaranVehicleReviewApproved(claimCase);
|
||||
const product = await this.resolveFanavaranClaimProduct(claimCaseId);
|
||||
if (
|
||||
!claimCase?.claimId ||
|
||||
@@ -7884,6 +7905,17 @@ export class ClaimRequestManagementService {
|
||||
return baseMessage;
|
||||
}
|
||||
|
||||
private assertFanavaranVehicleReviewApproved(claimCase: any): void {
|
||||
const review = claimCase?.fanavaranVehicleReview;
|
||||
const ids = [review?.vehicleGroup?.id, review?.vehicleUseType?.id, review?.vehicleSystem?.id, review?.vehicleKind?.id];
|
||||
if (review?.approved !== true || ids.some((id) => !Number.isInteger(Number(id)) || Number(id) <= 0)) {
|
||||
throw new ConflictException({
|
||||
code: "FANAVARAN_VEHICLE_REVIEW_REQUIRED",
|
||||
message: "An expert must review and approve the vehicle group, use type, system, and kind before any data can be sent to Fanavaran.",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async getFanavaranAutoSubmitSkipReason(
|
||||
claimCase: any,
|
||||
): Promise<string | null> {
|
||||
@@ -7891,6 +7923,10 @@ export class ClaimRequestManagementService {
|
||||
return "Already submitted to Fanavaran";
|
||||
}
|
||||
|
||||
if (!claimCase.fanavaranVehicleReview?.approved) {
|
||||
return "Expert vehicle review is required before Fanavaran submission";
|
||||
}
|
||||
|
||||
if (!claimCase.blameRequestId) {
|
||||
return "Blame case not linked to claim case";
|
||||
}
|
||||
@@ -8199,6 +8235,7 @@ export class ClaimRequestManagementService {
|
||||
if (!claimCase) {
|
||||
throw new NotFoundException("Claim case not found");
|
||||
}
|
||||
this.assertFanavaranVehicleReviewApproved(claimCase);
|
||||
if (!claimCase.claimId) {
|
||||
await this.ensureFanavaranBaseClaim(claimCaseId, clientKey, auditSource);
|
||||
claimCase = await this.claimCaseDbService.findById(claimCaseId);
|
||||
@@ -8967,6 +9004,8 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!existing) throw new NotFoundException("Claim case not found");
|
||||
this.assertFanavaranVehicleReviewApproved(existing);
|
||||
|
||||
const auditSession: FanavaranAuditSession = {
|
||||
trackingCode: this.fanavaranAuditService.generateTrackingCode(),
|
||||
|
||||
Reference in New Issue
Block a user