forked from Yara724/api
Merge pull request 'main' (#322) from s.hajizadeh/yara724api:main into main
Reviewed-on: Yara724/api#322
This commit is contained in:
@@ -50,6 +50,7 @@ import {
|
||||
type FanavaranClaimProduct,
|
||||
} from "./fanavaran-claim-product";
|
||||
import {
|
||||
collectFanavaranExpertiseReadinessWarnings,
|
||||
hullExpertiseAssertFields,
|
||||
pickHullVehicleIdentity,
|
||||
toFanavaranHullExpertiseDmgSection,
|
||||
@@ -6154,6 +6155,7 @@ export class ClaimRequestManagementService {
|
||||
|
||||
const url = `${await this.fanavaranClaimsUrlForClaim(claimCaseId)}/${claimCase.claimId}/files`;
|
||||
const fileTypeId = profile.defaults.ClaimFileTypeId;
|
||||
const product = await this.resolveFanavaranClaimProduct(claimCaseId);
|
||||
|
||||
const logPrefix = `[Fanavaran ${clientKey} V2 Attachment Batch] claimCaseId=${claimCaseId}`;
|
||||
|
||||
@@ -6164,6 +6166,7 @@ export class ClaimRequestManagementService {
|
||||
const content = {
|
||||
FileName: candidate.fileName,
|
||||
FileTypeId: fileTypeId,
|
||||
...(product === "car-body" ? { ClaimId: claimCase.claimId } : {}),
|
||||
};
|
||||
|
||||
this.logger.log(
|
||||
@@ -6187,6 +6190,7 @@ export class ClaimRequestManagementService {
|
||||
submitted: true,
|
||||
claimId: claimCase.claimId,
|
||||
fileName: candidate.fileName,
|
||||
submitUrl: url,
|
||||
fanavaranResponse: response.data,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -6199,6 +6203,8 @@ export class ClaimRequestManagementService {
|
||||
submitted: false,
|
||||
warning,
|
||||
fileName: candidate.fileName,
|
||||
claimId: claimCase.claimId,
|
||||
submitUrl: url,
|
||||
});
|
||||
|
||||
// Schedule a retry for this individual file via autoSubmitFanavaranAttachment,
|
||||
@@ -6318,6 +6324,10 @@ export class ClaimRequestManagementService {
|
||||
Files: [
|
||||
{ FileName: fileName, FileTypeId: profile.defaults.ClaimFileTypeId },
|
||||
],
|
||||
...((await this.resolveFanavaranClaimProduct(claimCaseId)) ===
|
||||
"car-body"
|
||||
? { ClaimId: claimCase.claimId }
|
||||
: {}),
|
||||
};
|
||||
|
||||
const auditSession: FanavaranAuditSession = {
|
||||
@@ -6793,36 +6803,15 @@ export class ClaimRequestManagementService {
|
||||
warnings: string[],
|
||||
options?: { requireDmgCaseId?: boolean; requireThirdPartyLookups?: boolean },
|
||||
): void {
|
||||
const sections = Array.isArray(payload.DmgSections)
|
||||
? payload.DmgSections
|
||||
: [];
|
||||
if (options?.requireDmgCaseId !== false && !payload.DmgCaseId)
|
||||
warnings.push("DmgCaseId is required.");
|
||||
if (options?.requireThirdPartyLookups !== false) {
|
||||
if (!payload.InspectionPlaceId)
|
||||
warnings.push("InspectionPlaceId is required.");
|
||||
if (!payload.DropAmountStatus)
|
||||
warnings.push("DropAmountStatus is required.");
|
||||
}
|
||||
if (!payload.InspectionPlaceId)
|
||||
warnings.push("InspectionPlaceId is required.");
|
||||
if (!payload.DropAmountStatus)
|
||||
warnings.push("DropAmountStatus is required.");
|
||||
if (!sections.length)
|
||||
warnings.push("At least one DmgSections row is required.");
|
||||
for (const [index, section] of sections.entries()) {
|
||||
const row = section as Record<string, unknown>;
|
||||
if (!row.DmgSectionId) {
|
||||
warnings.push(`DmgSections[${index}].DmgSectionId is required.`);
|
||||
}
|
||||
if (!row.AccidentLevel) {
|
||||
warnings.push(`DmgSections[${index}].AccidentLevel is required.`);
|
||||
}
|
||||
}
|
||||
if (warnings.length) {
|
||||
const readyWarnings = collectFanavaranExpertiseReadinessWarnings(
|
||||
payload,
|
||||
options,
|
||||
);
|
||||
const allWarnings = Array.from(new Set([...warnings, ...readyWarnings]));
|
||||
if (allWarnings.length) {
|
||||
throw new BadRequestException({
|
||||
message: "Fanavaran expertise payload is not ready.",
|
||||
warnings: Array.from(new Set(warnings)),
|
||||
warnings: allWarnings,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { PartyRole } from "src/request-management/entities/schema/partyRole.enum";
|
||||
import {
|
||||
hullExpertiseAssertFields,
|
||||
collectFanavaranExpertiseReadinessWarnings,
|
||||
pickHullVehicleIdentity,
|
||||
toFanavaranHullExpertiseDmgSection,
|
||||
toFanavaranHullExpertisePayload,
|
||||
@@ -95,4 +97,60 @@ describe("fanavaran hull expertise", () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not require ثالث expertise fields on a GEN.06 hull payload", () => {
|
||||
const payload = toFanavaranHullExpertisePayload({
|
||||
claimExpertId: 29,
|
||||
dmgAssessmentDate: "1405/06/24",
|
||||
inspectionTime: "10:41",
|
||||
wage: 6000000,
|
||||
componentReplacementCost: 10000000,
|
||||
wasteValue: 0,
|
||||
dropAmount: 10000,
|
||||
vehicleCurrentValue: null,
|
||||
vehicle: {
|
||||
motorNo: "13389030167",
|
||||
chassisNo: "NAAP41FD5BJ301065",
|
||||
vin: "IRFC891V7D2301065",
|
||||
plaqueNo: "56د394",
|
||||
plaqueSerial: "66",
|
||||
builtYear: 1389,
|
||||
},
|
||||
dmgSections: [
|
||||
toFanavaranHullExpertiseDmgSection({
|
||||
partId: 9,
|
||||
desc: "سپر جلو",
|
||||
wasteValue: 0,
|
||||
amount: 11000000,
|
||||
}),
|
||||
toFanavaranHullExpertiseDmgSection({
|
||||
partId: 11,
|
||||
desc: "آينه سمت راننده",
|
||||
wasteValue: 0,
|
||||
amount: 5000000,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(
|
||||
collectFanavaranExpertiseReadinessWarnings(
|
||||
payload,
|
||||
hullExpertiseAssertFields("car-body"),
|
||||
),
|
||||
).toEqual([]);
|
||||
expect(
|
||||
collectFanavaranExpertiseReadinessWarnings(
|
||||
payload,
|
||||
hullExpertiseAssertFields("third-party"),
|
||||
),
|
||||
).toEqual([
|
||||
"DmgCaseId is required.",
|
||||
"InspectionPlaceId is required.",
|
||||
"DropAmountStatus is required.",
|
||||
"DmgSections[0].DmgSectionId is required.",
|
||||
"DmgSections[0].AccidentLevel is required.",
|
||||
"DmgSections[1].DmgSectionId is required.",
|
||||
"DmgSections[1].AccidentLevel is required.",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -122,3 +122,39 @@ export function hullExpertiseAssertFields(
|
||||
}
|
||||
return { requireDmgCaseId: true, requireThirdPartyLookups: true };
|
||||
}
|
||||
|
||||
export function collectFanavaranExpertiseReadinessWarnings(
|
||||
payload: Record<string, unknown>,
|
||||
options?: { requireDmgCaseId?: boolean; requireThirdPartyLookups?: boolean },
|
||||
): string[] {
|
||||
const warnings: string[] = [];
|
||||
const sections = Array.isArray(payload.DmgSections)
|
||||
? payload.DmgSections
|
||||
: [];
|
||||
const thirdPartyLookups = options?.requireThirdPartyLookups !== false;
|
||||
if (options?.requireDmgCaseId !== false && !payload.DmgCaseId) {
|
||||
warnings.push("DmgCaseId is required.");
|
||||
}
|
||||
if (thirdPartyLookups) {
|
||||
if (!payload.InspectionPlaceId) {
|
||||
warnings.push("InspectionPlaceId is required.");
|
||||
}
|
||||
if (!payload.DropAmountStatus) {
|
||||
warnings.push("DropAmountStatus is required.");
|
||||
}
|
||||
}
|
||||
if (!sections.length) {
|
||||
warnings.push("At least one DmgSections row is required.");
|
||||
}
|
||||
for (const [index, section] of sections.entries()) {
|
||||
const row = section as Record<string, unknown>;
|
||||
if (!thirdPartyLookups) continue;
|
||||
if (!row.DmgSectionId) {
|
||||
warnings.push(`DmgSections[${index}].DmgSectionId is required.`);
|
||||
}
|
||||
if (!row.AccidentLevel) {
|
||||
warnings.push(`DmgSections[${index}].AccidentLevel is required.`);
|
||||
}
|
||||
}
|
||||
return Array.from(new Set(warnings));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user