From af9bed3b0d0f099fa223eb03f4d09bb5a234fdf5 Mon Sep 17 00:00:00 2001 From: "s.hajizadeh" Date: Thu, 12 Nov 2026 13:01:32 +0330 Subject: [PATCH] vehicle hull accessories debug , either success or clear YARA error --- docs/fanavaran/car-body-stage-fields.md | 2 +- docs/fanavaran/request-lookup-fields.md | 10 +-- .../claim-request-management.service.ts | 50 +++++++++++--- .../fanavaran-hull-accessory-mapping.spec.ts | 39 +++++++++-- .../fanavaran-hull-expertise-lookups.ts | 67 +++++++++++++------ .../fanavaran-hull-expertise.ts | 14 +++- 6 files changed, 140 insertions(+), 42 deletions(-) diff --git a/docs/fanavaran/car-body-stage-fields.md b/docs/fanavaran/car-body-stage-fields.md index c3526aa..c5dbbb6 100644 --- a/docs/fanavaran/car-body-stage-fields.md +++ b/docs/fanavaran/car-body-stage-fields.md @@ -142,7 +142,7 @@ Not ثالث GEN.08: no `DmgCaseId`, `InspectionPlaceId`, `RepairWage` on the ro | DmgSections[].WasteValue | داغی ردیف | number | **no** | **user** | | 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[].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[].Amount | مبلغ (قطعه+اجرت) | number | **no** | **user** | | DmgSections[].DmgSectionCosts[].DmgCostKindId | نوع هزینه | number | **no** | Current `vehicle-hull-dmg-cost-kinds` API row caption مجموع لوازم; no numeric fallback | diff --git a/docs/fanavaran/request-lookup-fields.md b/docs/fanavaran/request-lookup-fields.md index 6d16d1e..ed91cc1 100644 --- a/docs/fanavaran/request-lookup-fields.md +++ b/docs/fanavaran/request-lookup-fields.md @@ -155,7 +155,7 @@ The returned attachment Id is saved as fileId; it is not FileTypeId. | Request field | Lookup/source | Current handling | |---|---|---| | 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[].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 | @@ -170,10 +170,10 @@ Get the policy accessory rows using: Upstream source: `GET /car/vehicle-hull-policies/{policyId}/dmg-accessories` -Use the row's Id for VehicleHullAccessoryId. Its PolicyId must be the claim's hull -PolicyId. A factory bundle may legitimately serve several different selected -car-components parts. Its bundle AccessoryKindId is not automatically the part ID -to send for every damaged part. +Use the row's Id for VehicleHullAccessoryId and that same row's AccessoryKindId. +Fanavaran rule `CarDamageBdAsibdideSectionLookupFilterRule` rejects pairing a +local car-components part id with an unrelated policy accessory Id (including +factory-bundle rows). If the policy list has no matching row, refuse submit. Hull has no damage-case POST. DmgCaseId, InspectionPlaceId and DropAmountStatus are not hull expertise fields. AccidentPercent is a percentage, not a lookup ID. diff --git a/src/claim-request-management/claim-request-management.service.ts b/src/claim-request-management/claim-request-management.service.ts index 6d1002c..0b36ffa 100644 --- a/src/claim-request-management/claim-request-management.service.ts +++ b/src/claim-request-management/claim-request-management.service.ts @@ -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 { diff --git a/src/claim-request-management/fanavaran-hull-accessory-mapping.spec.ts b/src/claim-request-management/fanavaran-hull-accessory-mapping.spec.ts index 2133945..ce1591b 100644 --- a/src/claim-request-management/fanavaran-hull-accessory-mapping.spec.ts +++ b/src/claim-request-management/fanavaran-hull-accessory-mapping.spec.ts @@ -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); + }); }); diff --git a/src/claim-request-management/fanavaran-hull-expertise-lookups.ts b/src/claim-request-management/fanavaran-hull-expertise-lookups.ts index 6652801..938af55 100644 --- a/src/claim-request-management/fanavaran-hull-expertise-lookups.ts +++ b/src/claim-request-management/fanavaran-hull-expertise-lookups.ts @@ -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 + ); +} diff --git a/src/claim-request-management/fanavaran-hull-expertise.ts b/src/claim-request-management/fanavaran-hull-expertise.ts index 5db533b..f98e3b5 100644 --- a/src/claim-request-management/fanavaran-hull-expertise.ts +++ b/src/claim-request-management/fanavaran-hull-expertise.ts @@ -196,7 +196,19 @@ export function collectFanavaranExpertiseReadinessWarnings( } for (const [index, section] of sections.entries()) { const row = section as Record; - 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.`); }