vehicle hull accessories debug , either success or clear YARA error

This commit is contained in:
2026-11-12 13:01:32 +03:30
parent 3fe897031a
commit af9bed3b0d
6 changed files with 140 additions and 42 deletions
+1 -1
View File
@@ -142,7 +142,7 @@ Not ثالث GEN.08: no `DmgCaseId`, `InspectionPlaceId`, `RepairWage` on the ro
| DmgSections[].WasteValue | داغی ردیف | number | **no** | **user** | | DmgSections[].WasteValue | داغی ردیف | number | **no** | **user** |
| DmgSections[].AccessoryKindId | نوع قطعه کاتالوگ | number | preferred | **user** `partId` · lookup `car-components` | | DmgSections[].AccessoryKindId | نوع قطعه کاتالوگ | number | preferred | **user** `partId` · lookup `car-components` |
| DmgSections[].DmgKindId | نوع آسیب بدنه | number | **no** | Current `vehicle-hull-dmg-kind` API row caption تخریب; no numeric fallback | | DmgSections[].DmgKindId | نوع آسیب بدنه | number | **no** | Current `vehicle-hull-dmg-kind` API row caption تخریب; no numeric fallback |
| DmgSections[].VehicleHullAccessoryId | شناسه لوازم بدنه | number | **no** | Current policy `dmg-accessories`: match `AccessoryKindId`, else that policy's factory bundle; warn and block submission if unresolved | | DmgSections[].VehicleHullAccessoryId | شناسه لوازم بدنه | number | **no** | Current policy `dmg-accessories` only: exact `AccessoryKindId` or caption match on the same row; **never** invent a factory-bundle Id. Block submit if unresolved |
| DmgSections[].DmgSectionCosts[].Caption | عنوان هزینه | string | **no** | **user** label | | DmgSections[].DmgSectionCosts[].Caption | عنوان هزینه | string | **no** | **user** label |
| DmgSections[].DmgSectionCosts[].Amount | مبلغ (قطعه+اجرت) | number | **no** | **user** | | DmgSections[].DmgSectionCosts[].Amount | مبلغ (قطعه+اجرت) | number | **no** | **user** |
| DmgSections[].DmgSectionCosts[].DmgCostKindId | نوع هزینه | number | **no** | Current `vehicle-hull-dmg-cost-kinds` API row caption مجموع لوازم; no numeric fallback | | DmgSections[].DmgSectionCosts[].DmgCostKindId | نوع هزینه | number | **no** | Current `vehicle-hull-dmg-cost-kinds` API row caption مجموع لوازم; no numeric fallback |
+5 -5
View File
@@ -155,7 +155,7 @@ The returned attachment Id is saved as fileId; it is not FileTypeId.
| Request field | Lookup/source | Current handling | | Request field | Lookup/source | Current handling |
|---|---|---| |---|---|---|
| DmgSections[].AccessoryKindId | car-components | Selected part ID, live checked | | DmgSections[].AccessoryKindId | car-components | Selected part ID, live checked |
| DmgSections[].VehicleHullAccessoryId | Current hull policy dmg-accessories | Exact matching accessory or that policy's factory bundle; live checked; never a shared fixed record ID | | DmgSections[].VehicleHullAccessoryId | Current hull policy dmg-accessories | Exact `AccessoryKindId` (or caption) match on one policy row; Id+kind must stay coherent; no factory-bundle guess; block submit if missing |
| DmgSections[].DmgKindId | vehicle-hull-dmg-kind | Response row caption تخریب; live checked, no numeric fallback | | DmgSections[].DmgKindId | vehicle-hull-dmg-kind | Response row caption تخریب; live checked, no numeric fallback |
| DmgSections[].DmgSectionCosts[].DmgCostKindId | vehicle-hull-dmg-cost-kinds | Response row caption مجموع لوازم; live checked, no numeric fallback | | DmgSections[].DmgSectionCosts[].DmgCostKindId | vehicle-hull-dmg-cost-kinds | Response row caption مجموع لوازم; live checked, no numeric fallback |
| ColorId | Policy vehicle GET ColorId | Inquiry-derived; not independently checked against a colour lookup | | ColorId | Policy vehicle GET ColorId | Inquiry-derived; not independently checked against a colour lookup |
@@ -170,10 +170,10 @@ Get the policy accessory rows using:
Upstream source: Upstream source:
`GET /car/vehicle-hull-policies/{policyId}/dmg-accessories` `GET /car/vehicle-hull-policies/{policyId}/dmg-accessories`
Use the row's Id for VehicleHullAccessoryId. Its PolicyId must be the claim's hull Use the row's Id for VehicleHullAccessoryId and that same row's AccessoryKindId.
PolicyId. A factory bundle may legitimately serve several different selected Fanavaran rule `CarDamageBdAsibdideSectionLookupFilterRule` rejects pairing a
car-components parts. Its bundle AccessoryKindId is not automatically the part ID local car-components part id with an unrelated policy accessory Id (including
to send for every damaged part. factory-bundle rows). If the policy list has no matching row, refuse submit.
Hull has no damage-case POST. DmgCaseId, InspectionPlaceId and DropAmountStatus Hull has no damage-case POST. DmgCaseId, InspectionPlaceId and DropAmountStatus
are not hull expertise fields. AccidentPercent is a percentage, not a lookup ID. are not hull expertise fields. AccidentPercent is a percentage, not a lookup ID.
@@ -215,7 +215,7 @@ import {
FANAVARAN_HULL_DMG_KIND_CAPTION, FANAVARAN_HULL_DMG_KIND_CAPTION,
findLookupIdByCaption, findLookupIdByCaption,
asHullDmgAccessoryRows, asHullDmgAccessoryRows,
resolveVehicleHullAccessoryId, resolveHullDmgSectionAccessory,
} from './fanavaran-hull-expertise-lookups'; } from './fanavaran-hull-expertise-lookups';
import { import {
validateFanavaranHullLookupIds, validateFanavaranHullLookupIds,
@@ -2769,7 +2769,11 @@ export class ClaimRequestManagementService {
); );
let accessories = asHullDmgAccessoryRows([]); 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) { if (policyId != null && input.parts.length > 0) {
try { try {
accessories = asHullDmgAccessoryRows( accessories = asHullDmgAccessoryRows(
@@ -2779,9 +2783,19 @@ export class ClaimRequestManagementService {
contractOptions, contractOptions,
), ),
); );
if (accessories.length === 0) {
input.warnings.push(
`VehicleHullAccessoryId cannot be resolved: policy ${policyId} dmg-accessories returned no rows.`,
);
}
} catch (error) { } catch (error) {
const message =
error instanceof Error ? error.message : String(error);
this.logger.warn( 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, 0,
); );
const hullSections = input.parts.map((part: any) => { const hullSections = input.parts.map((part: any, index: number) => {
const vehicleHullAccessoryId = resolveVehicleHullAccessoryId( const partLabel = this.fanavaranPartLabel(part);
const resolved = resolveHullDmgSectionAccessory(
accessories, accessories,
parseFanavaranId(part?.partId), 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({ return toFanavaranHullExpertiseDmgSection({
partId: part?.partId, partId: resolved?.accessoryKindId ?? part?.partId,
desc: this.fanavaranPartLabel(part), desc: partLabel,
wasteValue: this.fanavaranDaghiWasteValue(part?.daghi), wasteValue: this.fanavaranDaghiWasteValue(part?.daghi),
amount: amount:
this.parseFanavaranMoney(part?.price) + this.parseFanavaranMoney(part?.price) +
this.parseFanavaranMoney(part?.salary), this.parseFanavaranMoney(part?.salary),
dmgKindId, dmgKindId,
dmgCostKindId, dmgCostKindId,
vehicleHullAccessoryId, vehicleHullAccessoryId: resolved?.vehicleHullAccessoryId ?? null,
}); });
}); });
@@ -5899,10 +5920,19 @@ export class ClaimRequestManagementService {
catalogKey?: unknown; catalogKey?: unknown;
}; };
return String( 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 { 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([ const { build } = setup([
{ Id: 900003, AccessoryDesc: "کليه قطعات فابريک" }, { Id: 900003, AccessoryDesc: "کليه قطعات فابريک" },
]); ]);
const { payload } = await build(); const { payload, warnings } = await build();
expect( expect(
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId), 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 () => { it("does not replace unavailable lookup values with 5485 or 1", async () => {
const { service, build } = setup([ const { service, build } = setup([
{ Id: 2810613, AccessoryDesc: "کليه قطعات فابريک" }, { Id: 2810613, AccessoryKindId: 9, AccessoryDesc: "سپر جلو" },
]); ]);
service.getFanavaranLookupRows.mockResolvedValue([]); service.getFanavaranLookupRows.mockResolvedValue([]);
const { payload, warnings } = await build(); const { payload, warnings } = await build();
@@ -103,7 +108,12 @@ describe("hull expertise policy accessory mapping", () => {
expect( expect(
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId), payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
).toEqual([null, null]); ).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 () => { 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]); ).toEqual([null, null]);
expect(warnings).toEqual( expect(warnings).toEqual(
expect.arrayContaining([ 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; return null;
} }
function isFactoryDefaultAccessoryRow( function normalizeAccessoryCaption(value: unknown): string {
row: FanavaranHullDmgAccessoryRow, return String(value ?? "")
): boolean { .replace(/ي/g, "ی")
const desc = String(row.AccessoryDesc ?? "").trim(); .replace(/ك/g, "ک")
return ( .replace(/\u200c/g, " ")
desc.includes("کليه قطعات فابريک") || .replace(/\s+/g, " ")
desc.includes("کلیه قطعات فابریک") || .trim();
desc.includes("کليه قطعات") ||
desc.includes("فابريک")
);
} }
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. * GEN.06 accessory pair from `GET …/vehicle-hull-policies/{policyId}/dmg-accessories`.
* 1) Match AccessoryKindId to car-components part id. * Only returns a coherent Id + AccessoryKindId from one policy row.
* 2) Else factory bundle row (app default outer parts map here on Parsian). * Never invents a factory-bundle Id with a different local part kind — that fails
* `CarDamageBdAsibdideSectionLookupFilterRule`.
*/ */
export function resolveVehicleHullAccessoryId( export function resolveHullDmgSectionAccessory(
accessories: FanavaranHullDmgAccessoryRow[], accessories: FanavaranHullDmgAccessoryRow[],
accessoryKindId: number | null, accessoryKindId: number | null,
): number | null { partCaption?: string | null,
): ResolvedHullDmgAccessory | null {
if (accessories.length === 0) return null; if (accessories.length === 0) return null;
if (accessoryKindId != null) { if (accessoryKindId != null) {
@@ -85,12 +90,36 @@ export function resolveVehicleHullAccessoryId(
(row) => parseFanavaranId(row.AccessoryKindId) === accessoryKindId, (row) => parseFanavaranId(row.AccessoryKindId) === accessoryKindId,
); );
const exactId = parseFanavaranId(exact?.Id); 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 wanted = normalizeAccessoryCaption(partCaption);
const factoryId = parseFanavaranId(factory?.Id); if (wanted) {
if (factoryId != null) return factoryId; 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; 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()) { for (const [index, section] of sections.entries()) {
const row = section as Record<string, unknown>; 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) { if (!row.DmgSectionId) {
warnings.push(`DmgSections[${index}].DmgSectionId is required.`); warnings.push(`DmgSections[${index}].DmgSectionId is required.`);
} }