forked from Yara724/api
done vehicle hull accessories
This commit is contained in:
@@ -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` only: exact `AccessoryKindId` or caption match on the same row; **never** invent a factory-bundle Id. Block submit if unresolved |
|
||||
| DmgSections[].VehicleHullAccessoryId | شناسه لوازم بدنه | number | preferred | Current policy `dmg-accessories`: exact `AccessoryKindId` or caption match; else the «کليه قطعات فابريک» factory-bundle row `Id`. Keep selected car-components `AccessoryKindId` + part `Desc` |
|
||||
| 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 |
|
||||
|
||||
@@ -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 `AccessoryKindId` (or caption) match on one policy row; Id+kind must stay coherent; no factory-bundle guess; block submit if missing |
|
||||
| DmgSections[].VehicleHullAccessoryId | Current hull policy dmg-accessories | Exact `AccessoryKindId` (or caption) match on one policy row. If missing, use the policy «کليه قطعات فابريک» row `Id` (factory bundle) while keeping the selected car-components `AccessoryKindId` and part `Desc` |
|
||||
| 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 |
|
||||
@@ -173,7 +173,14 @@ Upstream source:
|
||||
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.
|
||||
factory-bundle rows).
|
||||
|
||||
`car-components` is the full part catalogue (frontend picker). Policy
|
||||
`dmg-accessories` is only what that hull policy registered — often a single
|
||||
«کليه قطعات فابريک» OEM/factory coverage line (AccessoryKindId e.g. 112), not
|
||||
every tyre/cap/electrical part. Unlisted parts map to that factory row's `Id`
|
||||
as `VehicleHullAccessoryId`, keep the selected car-components `AccessoryKindId`,
|
||||
and keep `Desc` from the car-components Caption when available.
|
||||
|
||||
Hull has no damage-case POST. DmgCaseId, InspectionPlaceId and DropAmountStatus
|
||||
are not hull expertise fields. AccidentPercent is a percentage, not a lookup ID.
|
||||
|
||||
@@ -213,7 +213,9 @@ import {
|
||||
import {
|
||||
FANAVARAN_HULL_DMG_COST_KIND_CAPTION,
|
||||
FANAVARAN_HULL_DMG_KIND_CAPTION,
|
||||
findLookupCaptionById,
|
||||
findLookupIdByCaption,
|
||||
findHullFactoryBundleAccessory,
|
||||
asHullDmgAccessoryRows,
|
||||
resolveHullDmgSectionAccessory,
|
||||
} from './fanavaran-hull-expertise-lookups';
|
||||
@@ -2849,20 +2851,35 @@ export class ClaimRequestManagementService {
|
||||
0,
|
||||
);
|
||||
|
||||
const factoryBundle = findHullFactoryBundleAccessory(accessories);
|
||||
const hullSections = input.parts.map((part: any, index: number) => {
|
||||
const partLabel = this.fanavaranPartLabel(part);
|
||||
const partKindId = parseFanavaranId(part?.partId);
|
||||
// Prefer live car-components Caption so Desc matches the frontend catalogue.
|
||||
const catalogueCaption = findLookupCaptionById(componentRows, partKindId);
|
||||
const localLabel = this.fanavaranPartLabel(part);
|
||||
const partLabel = catalogueCaption || localLabel;
|
||||
const resolved = resolveHullDmgSectionAccessory(
|
||||
accessories,
|
||||
parseFanavaranId(part?.partId),
|
||||
partKindId,
|
||||
partLabel,
|
||||
);
|
||||
if (!resolved) {
|
||||
// No per-part policy row → cover under «کليه قطعات فابريک» Id (e.g. 3061139).
|
||||
// Keep the selected car-components AccessoryKindId; Desc stays the specific part.
|
||||
let vehicleHullAccessoryId = resolved?.vehicleHullAccessoryId ?? null;
|
||||
let accessoryKindId: number | string | null | undefined =
|
||||
resolved?.accessoryKindId ?? part?.partId;
|
||||
if (!resolved && factoryBundle) {
|
||||
vehicleHullAccessoryId = factoryBundle.vehicleHullAccessoryId;
|
||||
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.`,
|
||||
`DmgSections[${index}] (${partLabel || part?.partId || 'part'}): AccessoryKindId=${part?.partId ?? '(missing)'} is not a separate policy dmg-accessories row; using factory bundle VehicleHullAccessoryId=${factoryBundle.vehicleHullAccessoryId} («کليه قطعات فابريک»).`,
|
||||
);
|
||||
} else 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)'}. Leaving VehicleHullAccessoryId null.`,
|
||||
);
|
||||
}
|
||||
return toFanavaranHullExpertiseDmgSection({
|
||||
partId: resolved?.accessoryKindId ?? part?.partId,
|
||||
partId: accessoryKindId,
|
||||
desc: partLabel,
|
||||
wasteValue: this.fanavaranDaghiWasteValue(part?.daghi),
|
||||
amount:
|
||||
@@ -2870,7 +2887,7 @@ export class ClaimRequestManagementService {
|
||||
this.parseFanavaranMoney(part?.salary),
|
||||
dmgKindId,
|
||||
dmgCostKindId,
|
||||
vehicleHullAccessoryId: resolved?.vehicleHullAccessoryId ?? null,
|
||||
vehicleHullAccessoryId,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -68,17 +68,24 @@ describe("hull expertise policy accessory mapping", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("does not invent a factory-bundle Id when AccessoryKindId is missing on that row", async () => {
|
||||
it("maps unmatched parts onto the policy factory-bundle VehicleHullAccessoryId", async () => {
|
||||
const { build } = setup([
|
||||
{ Id: 900003, AccessoryDesc: "کليه قطعات فابريک" },
|
||||
{
|
||||
Id: 3061139,
|
||||
AccessoryKindId: 112,
|
||||
AccessoryDesc: "کليه قطعات فابريک",
|
||||
},
|
||||
]);
|
||||
const { payload, warnings } = await build();
|
||||
expect(
|
||||
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
|
||||
).toEqual([null, null]);
|
||||
).toEqual([3061139, 3061139]);
|
||||
expect(payload.DmgSections.map((row: any) => row.AccessoryKindId)).toEqual([
|
||||
9, 13,
|
||||
]);
|
||||
expect(warnings).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("Refusing to invent VehicleHullAccessoryId"),
|
||||
expect.stringContaining("using factory bundle VehicleHullAccessoryId=3061139"),
|
||||
]),
|
||||
);
|
||||
});
|
||||
@@ -111,7 +118,7 @@ describe("hull expertise policy accessory mapping", () => {
|
||||
expect(warnings).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("dmg-accessories lookup failed"),
|
||||
expect.stringContaining("Refusing to invent VehicleHullAccessoryId"),
|
||||
expect.stringContaining("Leaving VehicleHullAccessoryId null"),
|
||||
]),
|
||||
);
|
||||
});
|
||||
@@ -140,7 +147,9 @@ describe("hull expertise policy accessory mapping", () => {
|
||||
).toEqual([null, null]);
|
||||
expect(warnings).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringMatching(/VehicleHullAccessoryId|Refusing to invent/),
|
||||
expect.stringMatching(
|
||||
/VehicleHullAccessoryId|Leaving VehicleHullAccessoryId null/,
|
||||
),
|
||||
]),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -31,32 +31,79 @@ export function asHullDmgAccessoryRows(
|
||||
return asLookupRows(value) as FanavaranHullDmgAccessoryRow[];
|
||||
}
|
||||
|
||||
export function findLookupIdByCaption(
|
||||
rows: unknown,
|
||||
caption: string,
|
||||
): number | null {
|
||||
const normalize = (raw: unknown) =>
|
||||
String(raw ?? "")
|
||||
function normalizeLookupCaption(raw: unknown): string {
|
||||
return String(raw ?? "")
|
||||
.replace(/ي/g, "ی")
|
||||
.replace(/ك/g, "ک")
|
||||
.replace(/\u200c/g, " ")
|
||||
.replace(/\s*([()])\s*/g, "$1")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
const target = normalize(caption);
|
||||
}
|
||||
|
||||
export function findLookupIdByCaption(
|
||||
rows: unknown,
|
||||
caption: string,
|
||||
): number | null {
|
||||
const target = normalizeLookupCaption(caption);
|
||||
for (const row of asLookupRows(rows)) {
|
||||
if (
|
||||
row.IsActive === false ||
|
||||
(row.IsActive != null && Number(row.IsActive) === 0)
|
||||
)
|
||||
continue;
|
||||
if (normalize(row.Caption) !== target) continue;
|
||||
if (normalizeLookupCaption(row.Caption) !== target) continue;
|
||||
const id = parseFanavaranId(row.Id);
|
||||
if (id != null) return id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Caption from car-components (or any Id/Caption lookup) for a selected part Id. */
|
||||
export function findLookupCaptionById(
|
||||
rows: unknown,
|
||||
id: number | null,
|
||||
): string | null {
|
||||
if (id == null) return null;
|
||||
for (const row of asLookupRows(rows)) {
|
||||
if (
|
||||
row.IsActive === false ||
|
||||
(row.IsActive != null && Number(row.IsActive) === 0)
|
||||
)
|
||||
continue;
|
||||
if (parseFanavaranId(row.Id) !== id) continue;
|
||||
const caption = normalizeLookupCaption(row.Caption);
|
||||
return caption || null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export type HullFactoryBundleAccessory = {
|
||||
vehicleHullAccessoryId: number;
|
||||
/** Present on most factory rows (e.g. 112); not written onto unmatched DmgSections. */
|
||||
accessoryKindId: number | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Policy row for «کليه قطعات فابريک» — OEM/factory-fitted coverage bundle.
|
||||
* Many hull policies list only this row instead of every car-components part.
|
||||
*/
|
||||
export function findHullFactoryBundleAccessory(
|
||||
accessories: FanavaranHullDmgAccessoryRow[],
|
||||
): HullFactoryBundleAccessory | null {
|
||||
for (const row of accessories) {
|
||||
const desc = normalizeAccessoryCaption(row.AccessoryDesc);
|
||||
if (!desc.includes("فابریک")) continue;
|
||||
const vehicleHullAccessoryId = parseFanavaranId(row.Id);
|
||||
if (vehicleHullAccessoryId == null) continue;
|
||||
return {
|
||||
vehicleHullAccessoryId,
|
||||
accessoryKindId: parseFanavaranId(row.AccessoryKindId),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function normalizeAccessoryCaption(value: unknown): string {
|
||||
return String(value ?? "")
|
||||
.replace(/ي/g, "ی")
|
||||
@@ -75,8 +122,8 @@ export type ResolvedHullDmgAccessory = {
|
||||
/**
|
||||
* 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`.
|
||||
* Exact/caption match only. Factory-bundle fallback for unmatched parts is applied
|
||||
* by the expertise builder (VehicleHullAccessoryId from «کليه قطعات فابريک»).
|
||||
*/
|
||||
export function resolveHullDmgSectionAccessory(
|
||||
accessories: FanavaranHullDmgAccessoryRow[],
|
||||
@@ -98,8 +145,11 @@ export function resolveHullDmgSectionAccessory(
|
||||
|
||||
const wanted = normalizeAccessoryCaption(partCaption);
|
||||
if (wanted) {
|
||||
// Do not fuzzy-match onto «کليه قطعات فابريک» — that would pair the factory
|
||||
// Id with a different local part kind and fail Fanavaran's filter rule.
|
||||
const byDesc = accessories.find((row) => {
|
||||
const desc = normalizeAccessoryCaption(row.AccessoryDesc);
|
||||
if (desc.includes("فابریک") && desc !== wanted) return false;
|
||||
return desc === wanted || desc.includes(wanted) || wanted.includes(desc);
|
||||
});
|
||||
const descId = parseFanavaranId(byDesc?.Id);
|
||||
|
||||
@@ -169,4 +169,42 @@ describe("fanavaran hull expertise", () => {
|
||||
"DmgSections[1].AccidentLevel is required.",
|
||||
]);
|
||||
});
|
||||
|
||||
it("allows null VehicleHullAccessoryId on hull readiness when AccessoryKindId is set", () => {
|
||||
const payload = toFanavaranHullExpertisePayload({
|
||||
claimExpertId: 29,
|
||||
dmgAssessmentDate: "1405/06/24",
|
||||
inspectionTime: "10:41",
|
||||
wage: 0,
|
||||
componentReplacementCost: 5000000,
|
||||
wasteValue: 0,
|
||||
dropAmount: 0,
|
||||
vehicleCurrentValue: null,
|
||||
vehicle: {
|
||||
motorNo: "1",
|
||||
chassisNo: "2",
|
||||
vin: "3",
|
||||
plaqueNo: "56د394",
|
||||
plaqueSerial: "66",
|
||||
builtYear: 1389,
|
||||
},
|
||||
dmgSections: [
|
||||
toFanavaranHullExpertiseDmgSection({
|
||||
partId: 17,
|
||||
desc: "لاستيک جلو چپ",
|
||||
wasteValue: 0,
|
||||
amount: 5000000,
|
||||
dmgKindId: 5485,
|
||||
dmgCostKindId: 1,
|
||||
vehicleHullAccessoryId: null,
|
||||
}),
|
||||
],
|
||||
});
|
||||
expect(
|
||||
collectFanavaranExpertiseReadinessWarnings(
|
||||
payload,
|
||||
hullExpertiseAssertFields("car-body"),
|
||||
),
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -197,14 +197,12 @@ export function collectFanavaranExpertiseReadinessWarnings(
|
||||
for (const [index, section] of sections.entries()) {
|
||||
const row = section as Record<string, unknown>;
|
||||
if (!thirdPartyLookups) {
|
||||
if (row.VehicleHullAccessoryId == null || row.VehicleHullAccessoryId === "") {
|
||||
warnings.push(
|
||||
`DmgSections[${index}].VehicleHullAccessoryId is required from the hull policy dmg-accessories lookup.`,
|
||||
);
|
||||
}
|
||||
// VehicleHullAccessoryId may be null: many hull policies only list the
|
||||
// factory bundle (کليه قطعات فابريک), not every car-components part.
|
||||
// Do not invent a factory Id with a mismatched AccessoryKindId.
|
||||
if (row.AccessoryKindId == null || row.AccessoryKindId === "") {
|
||||
warnings.push(
|
||||
`DmgSections[${index}].AccessoryKindId is required from the matched policy accessory row.`,
|
||||
`DmgSections[${index}].AccessoryKindId is required from car-components (selected part).`,
|
||||
);
|
||||
}
|
||||
continue;
|
||||
|
||||
@@ -61,11 +61,13 @@ export async function validateFanavaranHullLookupIds(
|
||||
"car-components",
|
||||
`${prefix}.AccessoryKindId`,
|
||||
);
|
||||
// Optional: policy often has only the factory-bundle row; null is allowed.
|
||||
add(
|
||||
row,
|
||||
"VehicleHullAccessoryId",
|
||||
"policy-dmg-accessories",
|
||||
`${prefix}.VehicleHullAccessoryId`,
|
||||
false,
|
||||
);
|
||||
add(row, "DmgKindId", "vehicle-hull-dmg-kind", `${prefix}.DmgKindId`);
|
||||
for (const [j, cost] of asLookupRows(row.DmgSectionCosts).entries())
|
||||
|
||||
Reference in New Issue
Block a user