This commit is contained in:
2026-09-19 15:38:00 +03:30
parent be06bfe1b5
commit 8afc1fabc4
5 changed files with 99 additions and 19 deletions

View File

@@ -51,8 +51,10 @@ import {
} from "./fanavaran-claim-product"; } from "./fanavaran-claim-product";
import { import {
actualPremiumFromHullPolicyRecord, actualPremiumFromHullPolicyRecord,
authorityCulpritIdFromDetectionRows,
customerIdFromHullPolicyRecord, customerIdFromHullPolicyRecord,
FANAVARAN_DEFAULT_HULL_CULPRIT_TYPE_ID, FANAVARAN_DEFAULT_HULL_AUTHORITY_CULPRIT_ID,
FANAVARAN_DEFAULT_HULL_CUSTOMER_FAULT_PERCENT,
fanavaranHullNestedClaimId, fanavaranHullNestedClaimId,
toFanavaranHullBaseClaimPayload, toFanavaranHullBaseClaimPayload,
} from "./fanavaran-hull-base-claim"; } from "./fanavaran-hull-base-claim";
@@ -4339,14 +4341,25 @@ export class ClaimRequestManagementService {
input.payload.AccidentCulpritId = accidentCulpritId; input.payload.AccidentCulpritId = accidentCulpritId;
} }
const culpritTypeId = input.payload.CustomerFaultPercent =
parseFanavaranId(input.payload.CulpritTypeId) ?? FANAVARAN_DEFAULT_HULL_CUSTOMER_FAULT_PERCENT;
FANAVARAN_DEFAULT_HULL_CULPRIT_TYPE_ID;
if ( if (parseFanavaranId(input.payload.AuthorityCulpritId) == null) {
input.payload.CustomerFaultPercent == null && try {
culpritTypeId === 300 const authorityRows = await this.getFanavaranLookupRows(
) { input.clientKey,
input.payload.CustomerFaultPercent = 100; "detection-accident-culprits",
);
input.payload.AuthorityCulpritId =
authorityCulpritIdFromDetectionRows(authorityRows);
} catch (error) {
this.logger.warn(
`${input.logPrefix} detection-accident-culprits lookup failed; using default AuthorityCulpritId=${FANAVARAN_DEFAULT_HULL_AUTHORITY_CULPRIT_ID}`,
error,
);
input.payload.AuthorityCulpritId =
FANAVARAN_DEFAULT_HULL_AUTHORITY_CULPRIT_ID;
}
} }
} }

View File

@@ -51,7 +51,17 @@ export const FANAVARAN_DEFAULT_HULL_ACCIDENT_TYPE_ID = 2;
export const FANAVARAN_HULL_ANS_NO = 0; export const FANAVARAN_HULL_ANS_NO = 0;
/** GEN.03 hull culprit type when third-party is at fault. Lookup: vehicle-hull-accident-culprit-type */ /** GEN.03 hull culprit type when third-party is at fault. Lookup: vehicle-hull-accident-culprit-type */
export const FANAVARAN_DEFAULT_HULL_CULPRIT_TYPE_ID = 301; export const FANAVARAN_DEFAULT_HULL_CULPRIT_TYPE_ID = 300;
/** GEN.03 required: درصد تقصير بيمه گذار. Proven Parsian submit uses 100. */
export const FANAVARAN_DEFAULT_HULL_CUSTOMER_FAULT_PERCENT = 100;
/**
* GEN.03 required: مرجع تعيين مقصر.
* Lookup: GET /lookups/detection-accident-culprits. Fallback is بیمه‌گذار.
*/
export const FANAVARAN_DEFAULT_HULL_AUTHORITY_CULPRIT_ID = 1;
export const FANAVARAN_HULL_AUTHORITY_CULPRIT_CAPTION = "بيمه گذار";
/** GEN.03 ActualPremium from GET car/vehicle-hull-policies/{PolicyId} → TotalPremium. */ /** GEN.03 ActualPremium from GET car/vehicle-hull-policies/{PolicyId} → TotalPremium. */
export function actualPremiumFromHullPolicyRecord( export function actualPremiumFromHullPolicyRecord(
@@ -63,6 +73,41 @@ export function actualPremiumFromHullPolicyRecord(
return Number.isFinite(n) && n >= 0 ? n : null; return Number.isFinite(n) && n >= 0 ? n : null;
} }
function normalizeHullCaption(value: unknown): string {
return String(value ?? "")
.replace(/ي/g, "ی")
.replace(/ك/g, "ک")
.replace(/\s+/g, " ")
.trim();
}
/** AuthorityCulpritId from GET /lookups/detection-accident-culprits. */
export function authorityCulpritIdFromDetectionRows(
rows: unknown,
): number {
const list = Array.isArray(rows) ? rows : [];
const wanted = normalizeHullCaption(
FANAVARAN_HULL_AUTHORITY_CULPRIT_CAPTION,
);
for (const row of list) {
if (!row || typeof row !== "object") continue;
const caption = normalizeHullCaption(
(row as { Caption?: unknown }).Caption,
);
if (!caption.includes(wanted)) continue;
const raw = (row as { Id?: unknown }).Id;
const n = typeof raw === "number" ? raw : Number(raw);
if (Number.isFinite(n) && n > 0) return n;
}
for (const row of list) {
if (!row || typeof row !== "object") continue;
const raw = (row as { Id?: unknown }).Id;
const n = typeof raw === "number" ? raw : Number(raw);
if (Number.isFinite(n) && n > 0) return n;
}
return FANAVARAN_DEFAULT_HULL_AUTHORITY_CULPRIT_ID;
}
/** Fallback AccidentCulpritId when parties inquiry is unavailable. */ /** Fallback AccidentCulpritId when parties inquiry is unavailable. */
export function customerIdFromHullPolicyRecord( export function customerIdFromHullPolicyRecord(
policy: Record<string, unknown> | null | undefined, policy: Record<string, unknown> | null | undefined,
@@ -108,15 +153,14 @@ export function toFanavaranHullBaseClaimPayload(
continue; continue;
} }
if (key === "CustomerFaultPercent") { if (key === "CustomerFaultPercent") {
const culpritType = next[key] =
built.CulpritTypeId ?? FANAVARAN_DEFAULT_HULL_CULPRIT_TYPE_ID; built.CustomerFaultPercent ??
if (built.CustomerFaultPercent != null) { FANAVARAN_DEFAULT_HULL_CUSTOMER_FAULT_PERCENT;
next[key] = built.CustomerFaultPercent; continue;
} else if (culpritType === 300) {
next[key] = 100;
} else {
next[key] = null;
} }
if (key === "AuthorityCulpritId") {
next[key] =
built.AuthorityCulpritId ?? FANAVARAN_DEFAULT_HULL_AUTHORITY_CULPRIT_ID;
continue; continue;
} }
next[key] = Object.prototype.hasOwnProperty.call(built, key) next[key] = Object.prototype.hasOwnProperty.call(built, key)

View File

@@ -26,6 +26,11 @@ export const FANAVARAN_REMOTE_LOOKUPS: FanavaranRemoteLookupDefinition[] = [
url: `${FANAVARAN_LOOKUP_BASE_URL}/car/code-list/vehicle-hull-accident-culprit-type`, url: `${FANAVARAN_LOOKUP_BASE_URL}/car/code-list/vehicle-hull-accident-culprit-type`,
cacheFile: "vehicle-hull-accident-culprit-type.json", cacheFile: "vehicle-hull-accident-culprit-type.json",
}, },
{
name: "detection-accident-culprits",
url: `${FANAVARAN_LOOKUP_BASE_URL}/car/base-info/detection-accident-culprits`,
cacheFile: "detection-accident-culprits.json",
},
{ {
name: "vehicle-hull-dmg-kind", name: "vehicle-hull-dmg-kind",
url: `${FANAVARAN_LOOKUP_BASE_URL}/car/code-list/vehicle-hull-dmg-kind`, url: `${FANAVARAN_LOOKUP_BASE_URL}/car/code-list/vehicle-hull-dmg-kind`,

View File

@@ -64,6 +64,20 @@ export class LookupsController {
return await this.lookupsService.getVehicleHullAccidentCulpritType(); return await this.lookupsService.getVehicleHullAccidentCulpritType();
} }
@Get("detection-accident-culprits")
@ApiOperation({
summary: "Fanavaran GEN.03 hull authority that determined the culprit",
description:
"Returns values for base-claim field AuthorityCulpritId from car/base-info/detection-accident-culprits.",
})
@ApiOkResponse({
description: "Returns Fanavaran detection-accident-culprits rows",
schema: { type: "array", items: { type: "object" } },
})
async getDetectionAccidentCulprits() {
return await this.lookupsService.getDetectionAccidentCulprits();
}
@Get("vehicle-hull-dmg-kind") @Get("vehicle-hull-dmg-kind")
@ApiOperation({ @ApiOperation({
summary: "Fanavaran GEN.06 hull damage kind lookup", summary: "Fanavaran GEN.06 hull damage kind lookup",

View File

@@ -114,6 +114,10 @@ export class LookupsService {
return await this.getClientRemoteLookup("vehicle-hull-accident-culprit-type"); return await this.getClientRemoteLookup("vehicle-hull-accident-culprit-type");
} }
async getDetectionAccidentCulprits(): Promise<any> {
return await this.getClientRemoteLookup("detection-accident-culprits");
}
async getVehicleHullDmgKind(): Promise<any> { async getVehicleHullDmgKind(): Promise<any> {
return await this.getClientRemoteLookup("vehicle-hull-dmg-kind"); return await this.getClientRemoteLookup("vehicle-hull-dmg-kind");
} }