Compare commits

...

3 Commits

Author SHA1 Message Date
cd36a0f2d4 Merge pull request 'main' (#329) from s.hajizadeh/yara724api:main into main
Reviewed-on: Yara724/api#329
2026-09-19 15:38:51 +03:30
ffaeb50c61 merge upstream 2026-09-19 15:38:13 +03:30
8afc1fabc4 fuck 2026-09-19 15:38:00 +03:30
5 changed files with 99 additions and 19 deletions

View File

@@ -51,8 +51,10 @@ import {
} from "./fanavaran-claim-product";
import {
actualPremiumFromHullPolicyRecord,
authorityCulpritIdFromDetectionRows,
customerIdFromHullPolicyRecord,
FANAVARAN_DEFAULT_HULL_CULPRIT_TYPE_ID,
FANAVARAN_DEFAULT_HULL_AUTHORITY_CULPRIT_ID,
FANAVARAN_DEFAULT_HULL_CUSTOMER_FAULT_PERCENT,
fanavaranHullNestedClaimId,
toFanavaranHullBaseClaimPayload,
} from "./fanavaran-hull-base-claim";
@@ -4339,14 +4341,25 @@ export class ClaimRequestManagementService {
input.payload.AccidentCulpritId = accidentCulpritId;
}
const culpritTypeId =
parseFanavaranId(input.payload.CulpritTypeId) ??
FANAVARAN_DEFAULT_HULL_CULPRIT_TYPE_ID;
if (
input.payload.CustomerFaultPercent == null &&
culpritTypeId === 300
) {
input.payload.CustomerFaultPercent = 100;
input.payload.CustomerFaultPercent =
FANAVARAN_DEFAULT_HULL_CUSTOMER_FAULT_PERCENT;
if (parseFanavaranId(input.payload.AuthorityCulpritId) == null) {
try {
const authorityRows = await this.getFanavaranLookupRows(
input.clientKey,
"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;
/** 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. */
export function actualPremiumFromHullPolicyRecord(
@@ -63,6 +73,41 @@ export function actualPremiumFromHullPolicyRecord(
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. */
export function customerIdFromHullPolicyRecord(
policy: Record<string, unknown> | null | undefined,
@@ -108,15 +153,14 @@ export function toFanavaranHullBaseClaimPayload(
continue;
}
if (key === "CustomerFaultPercent") {
const culpritType =
built.CulpritTypeId ?? FANAVARAN_DEFAULT_HULL_CULPRIT_TYPE_ID;
if (built.CustomerFaultPercent != null) {
next[key] = built.CustomerFaultPercent;
} else if (culpritType === 300) {
next[key] = 100;
} else {
next[key] = null;
}
next[key] =
built.CustomerFaultPercent ??
FANAVARAN_DEFAULT_HULL_CUSTOMER_FAULT_PERCENT;
continue;
}
if (key === "AuthorityCulpritId") {
next[key] =
built.AuthorityCulpritId ?? FANAVARAN_DEFAULT_HULL_AUTHORITY_CULPRIT_ID;
continue;
}
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`,
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",
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();
}
@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")
@ApiOperation({
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");
}
async getDetectionAccidentCulprits(): Promise<any> {
return await this.getClientRemoteLookup("detection-accident-culprits");
}
async getVehicleHullDmgKind(): Promise<any> {
return await this.getClientRemoteLookup("vehicle-hull-dmg-kind");
}