forked from Yara724/api
vehicle hull accessories debug , either success or clear YARA error
This commit is contained in:
@@ -215,7 +215,7 @@ import {
|
||||
FANAVARAN_HULL_DMG_KIND_CAPTION,
|
||||
findLookupIdByCaption,
|
||||
asHullDmgAccessoryRows,
|
||||
resolveVehicleHullAccessoryId,
|
||||
resolveHullDmgSectionAccessory,
|
||||
} from './fanavaran-hull-expertise-lookups';
|
||||
import {
|
||||
validateFanavaranHullLookupIds,
|
||||
@@ -2769,7 +2769,11 @@ export class ClaimRequestManagementService {
|
||||
);
|
||||
|
||||
let accessories = asHullDmgAccessoryRows([]);
|
||||
if (policyId == null && input.parts.length > 0) input.warnings.push('VehicleHullAccessoryId cannot be resolved: missing PolicyId.');
|
||||
if (policyId == null && input.parts.length > 0) {
|
||||
input.warnings.push(
|
||||
'VehicleHullAccessoryId cannot be resolved: missing PolicyId for hull policy dmg-accessories.',
|
||||
);
|
||||
}
|
||||
if (policyId != null && input.parts.length > 0) {
|
||||
try {
|
||||
accessories = asHullDmgAccessoryRows(
|
||||
@@ -2779,9 +2783,19 @@ export class ClaimRequestManagementService {
|
||||
contractOptions,
|
||||
),
|
||||
);
|
||||
if (accessories.length === 0) {
|
||||
input.warnings.push(
|
||||
`VehicleHullAccessoryId cannot be resolved: policy ${policyId} dmg-accessories returned no rows.`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error ? error.message : String(error);
|
||||
this.logger.warn(
|
||||
`[buildCarBodyFanavaranExpertisePayload] policy ${policyId} dmg-accessories lookup failed: ${error instanceof Error ? error.message : error}`,
|
||||
`[buildCarBodyFanavaranExpertisePayload] policy ${policyId} dmg-accessories lookup failed: ${message}`,
|
||||
);
|
||||
input.warnings.push(
|
||||
`VehicleHullAccessoryId cannot be resolved: policy ${policyId} dmg-accessories lookup failed (${message}).`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2828,21 +2842,28 @@ export class ClaimRequestManagementService {
|
||||
0,
|
||||
);
|
||||
|
||||
const hullSections = input.parts.map((part: any) => {
|
||||
const vehicleHullAccessoryId = resolveVehicleHullAccessoryId(
|
||||
const hullSections = input.parts.map((part: any, index: number) => {
|
||||
const partLabel = this.fanavaranPartLabel(part);
|
||||
const resolved = resolveHullDmgSectionAccessory(
|
||||
accessories,
|
||||
parseFanavaranId(part?.partId),
|
||||
partLabel,
|
||||
);
|
||||
if (!resolved) {
|
||||
input.warnings.push(
|
||||
`DmgSections[${index}] (${partLabel || part?.partId || 'part'}): no matching row in policy ${policyId ?? '(missing)'} dmg-accessories for AccessoryKindId=${part?.partId ?? '(missing)'}. Refusing to invent VehicleHullAccessoryId.`,
|
||||
);
|
||||
}
|
||||
return toFanavaranHullExpertiseDmgSection({
|
||||
partId: part?.partId,
|
||||
desc: this.fanavaranPartLabel(part),
|
||||
partId: resolved?.accessoryKindId ?? part?.partId,
|
||||
desc: partLabel,
|
||||
wasteValue: this.fanavaranDaghiWasteValue(part?.daghi),
|
||||
amount:
|
||||
this.parseFanavaranMoney(part?.price) +
|
||||
this.parseFanavaranMoney(part?.salary),
|
||||
dmgKindId,
|
||||
dmgCostKindId,
|
||||
vehicleHullAccessoryId,
|
||||
vehicleHullAccessoryId: resolved?.vehicleHullAccessoryId ?? null,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5899,10 +5920,19 @@ export class ClaimRequestManagementService {
|
||||
catalogKey?: unknown;
|
||||
};
|
||||
return String(
|
||||
d.label_fa ?? d.part ?? d.name ?? d.catalogKey ?? part?.partId ?? '',
|
||||
d.label_fa ??
|
||||
d.part ??
|
||||
d.name ??
|
||||
d.catalogKey ??
|
||||
part?.partName ??
|
||||
part?.name ??
|
||||
part?.partId ??
|
||||
'',
|
||||
);
|
||||
}
|
||||
return String(damage ?? part?.partId ?? '');
|
||||
return String(
|
||||
damage ?? part?.partName ?? part?.name ?? part?.partId ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
private fanavaranDaghiWasteValue(daghi: unknown): number {
|
||||
|
||||
@@ -68,19 +68,24 @@ describe("hull expertise policy accessory mapping", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("uses a factory bundle only when it belongs to the current policy", async () => {
|
||||
it("does not invent a factory-bundle Id when AccessoryKindId is missing on that row", async () => {
|
||||
const { build } = setup([
|
||||
{ Id: 900003, AccessoryDesc: "کليه قطعات فابريک" },
|
||||
]);
|
||||
const { payload } = await build();
|
||||
const { payload, warnings } = await build();
|
||||
expect(
|
||||
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
|
||||
).toEqual([900003, 900003]);
|
||||
).toEqual([null, null]);
|
||||
expect(warnings).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("Refusing to invent VehicleHullAccessoryId"),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("does not replace unavailable lookup values with 5485 or 1", async () => {
|
||||
const { service, build } = setup([
|
||||
{ Id: 2810613, AccessoryDesc: "کليه قطعات فابريک" },
|
||||
{ Id: 2810613, AccessoryKindId: 9, AccessoryDesc: "سپر جلو" },
|
||||
]);
|
||||
service.getFanavaranLookupRows.mockResolvedValue([]);
|
||||
const { payload, warnings } = await build();
|
||||
@@ -103,7 +108,12 @@ describe("hull expertise policy accessory mapping", () => {
|
||||
expect(
|
||||
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
|
||||
).toEqual([null, null]);
|
||||
expect(warnings).toHaveLength(2);
|
||||
expect(warnings).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("dmg-accessories lookup failed"),
|
||||
expect.stringContaining("Refusing to invent VehicleHullAccessoryId"),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("reports a missing hull PolicyId instead of using the claim ID as a policy", async () => {
|
||||
@@ -130,9 +140,26 @@ describe("hull expertise policy accessory mapping", () => {
|
||||
).toEqual([null, null]);
|
||||
expect(warnings).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("VehicleHullAccessoryId"),
|
||||
expect.stringMatching(/VehicleHullAccessoryId|Refusing to invent/),
|
||||
]),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("matches by part caption and keeps AccessoryKindId from that policy row", async () => {
|
||||
const { build } = setup([
|
||||
{
|
||||
Id: 900010,
|
||||
AccessoryKindId: 44,
|
||||
AccessoryDesc: "سپر جلو",
|
||||
},
|
||||
]);
|
||||
const { payload, warnings } = await build();
|
||||
expect(payload.DmgSections[0]).toMatchObject({
|
||||
VehicleHullAccessoryId: 900010,
|
||||
AccessoryKindId: 44,
|
||||
});
|
||||
expect(payload.DmgSections[1].VehicleHullAccessoryId).toBeNull();
|
||||
expect(warnings.some((w) => w.includes("چراغ جلو چپ"))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,27 +57,32 @@ export function findLookupIdByCaption(
|
||||
return null;
|
||||
}
|
||||
|
||||
function isFactoryDefaultAccessoryRow(
|
||||
row: FanavaranHullDmgAccessoryRow,
|
||||
): boolean {
|
||||
const desc = String(row.AccessoryDesc ?? "").trim();
|
||||
return (
|
||||
desc.includes("کليه قطعات فابريک") ||
|
||||
desc.includes("کلیه قطعات فابریک") ||
|
||||
desc.includes("کليه قطعات") ||
|
||||
desc.includes("فابريک")
|
||||
);
|
||||
function normalizeAccessoryCaption(value: unknown): string {
|
||||
return String(value ?? "")
|
||||
.replace(/ي/g, "ی")
|
||||
.replace(/ك/g, "ک")
|
||||
.replace(/\u200c/g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
export type ResolvedHullDmgAccessory = {
|
||||
vehicleHullAccessoryId: number;
|
||||
/** Must come from the same policy dmg-accessories row (Fanavaran filter rule). */
|
||||
accessoryKindId: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* GEN.06 VehicleHullAccessoryId from policy dmg-accessories.
|
||||
* 1) Match AccessoryKindId to car-components part id.
|
||||
* 2) Else factory bundle row (app default outer parts map here on Parsian).
|
||||
* GEN.06 accessory pair from `GET …/vehicle-hull-policies/{policyId}/dmg-accessories`.
|
||||
* Only returns a coherent Id + AccessoryKindId from one policy row.
|
||||
* Never invents a factory-bundle Id with a different local part kind — that fails
|
||||
* `CarDamageBdAsibdideSectionLookupFilterRule`.
|
||||
*/
|
||||
export function resolveVehicleHullAccessoryId(
|
||||
export function resolveHullDmgSectionAccessory(
|
||||
accessories: FanavaranHullDmgAccessoryRow[],
|
||||
accessoryKindId: number | null,
|
||||
): number | null {
|
||||
partCaption?: string | null,
|
||||
): ResolvedHullDmgAccessory | null {
|
||||
if (accessories.length === 0) return null;
|
||||
|
||||
if (accessoryKindId != null) {
|
||||
@@ -85,12 +90,36 @@ export function resolveVehicleHullAccessoryId(
|
||||
(row) => parseFanavaranId(row.AccessoryKindId) === accessoryKindId,
|
||||
);
|
||||
const exactId = parseFanavaranId(exact?.Id);
|
||||
if (exactId != null) return exactId;
|
||||
const exactKind = parseFanavaranId(exact?.AccessoryKindId);
|
||||
if (exactId != null && exactKind != null) {
|
||||
return { vehicleHullAccessoryId: exactId, accessoryKindId: exactKind };
|
||||
}
|
||||
}
|
||||
|
||||
const factory = accessories.find(isFactoryDefaultAccessoryRow);
|
||||
const factoryId = parseFanavaranId(factory?.Id);
|
||||
if (factoryId != null) return factoryId;
|
||||
const wanted = normalizeAccessoryCaption(partCaption);
|
||||
if (wanted) {
|
||||
const byDesc = accessories.find((row) => {
|
||||
const desc = normalizeAccessoryCaption(row.AccessoryDesc);
|
||||
return desc === wanted || desc.includes(wanted) || wanted.includes(desc);
|
||||
});
|
||||
const descId = parseFanavaranId(byDesc?.Id);
|
||||
const descKind = parseFanavaranId(byDesc?.AccessoryKindId);
|
||||
if (descId != null && descKind != null) {
|
||||
return { vehicleHullAccessoryId: descId, accessoryKindId: descKind };
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @deprecated Prefer {@link resolveHullDmgSectionAccessory} — keeps Id/kind coherent. */
|
||||
export function resolveVehicleHullAccessoryId(
|
||||
accessories: FanavaranHullDmgAccessoryRow[],
|
||||
accessoryKindId: number | null,
|
||||
partCaption?: string | null,
|
||||
): number | null {
|
||||
return (
|
||||
resolveHullDmgSectionAccessory(accessories, accessoryKindId, partCaption)
|
||||
?.vehicleHullAccessoryId ?? null
|
||||
);
|
||||
}
|
||||
|
||||
@@ -196,7 +196,19 @@ export function collectFanavaranExpertiseReadinessWarnings(
|
||||
}
|
||||
for (const [index, section] of sections.entries()) {
|
||||
const row = section as Record<string, unknown>;
|
||||
if (!thirdPartyLookups) continue;
|
||||
if (!thirdPartyLookups) {
|
||||
if (row.VehicleHullAccessoryId == null || row.VehicleHullAccessoryId === "") {
|
||||
warnings.push(
|
||||
`DmgSections[${index}].VehicleHullAccessoryId is required from the hull policy dmg-accessories lookup.`,
|
||||
);
|
||||
}
|
||||
if (row.AccessoryKindId == null || row.AccessoryKindId === "") {
|
||||
warnings.push(
|
||||
`DmgSections[${index}].AccessoryKindId is required from the matched policy accessory row.`,
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!row.DmgSectionId) {
|
||||
warnings.push(`DmgSections[${index}].DmgSectionId is required.`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user