forked from Yara724/api
update the IsLicenseReplaced and for the accessories
This commit is contained in:
@@ -47,14 +47,13 @@ export const FANAVARAN_HULL_BASE_CLAIM_KEYS = [
|
||||
"CostSeparationToDmgSections",
|
||||
] as const;
|
||||
|
||||
/** GEN.03 default: تصادف(حادثه). Lookup: GET /lookups/vehicle-hull-accident-types */
|
||||
export const FANAVARAN_DEFAULT_HULL_ACCIDENT_TYPE_ID = 2;
|
||||
/** Select the current API row for the default collision scenario. */
|
||||
export const FANAVARAN_HULL_ACCIDENT_TYPE_CAPTION = "تصادف(حادثه)";
|
||||
|
||||
/** GEN.03 ans (0=خیر). Used for CostSeparationToDmgSections, IsOwnerChanged, IsLicenseReplaced. */
|
||||
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 = 300;
|
||||
export const FANAVARAN_HULL_CULPRIT_TYPE_CAPTION = "بيمه گذار";
|
||||
|
||||
/** GEN.03 required: درصد تقصير بيمه گذار. Proven Parsian submit uses 100. */
|
||||
export const FANAVARAN_DEFAULT_HULL_CUSTOMER_FAULT_PERCENT = 100;
|
||||
@@ -63,7 +62,6 @@ 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. */
|
||||
@@ -72,6 +70,7 @@ export function actualPremiumFromHullPolicyRecord(
|
||||
): number | null {
|
||||
if (!policy) return null;
|
||||
const raw = policy.TotalPremium ?? policy.totalPremium;
|
||||
if (raw == null || raw === "") return null;
|
||||
const n = typeof raw === "number" ? raw : Number(raw);
|
||||
return Number.isFinite(n) && n >= 0 ? n : null;
|
||||
}
|
||||
@@ -80,6 +79,7 @@ function normalizeHullCaption(value: unknown): string {
|
||||
return String(value ?? "")
|
||||
.replace(/ي/g, "ی")
|
||||
.replace(/ك/g, "ک")
|
||||
.replace(/\u200c/g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
@@ -87,13 +87,15 @@ function normalizeHullCaption(value: unknown): string {
|
||||
/** AuthorityCulpritId from GET /lookups/detection-accident-culprits. */
|
||||
export function authorityCulpritIdFromDetectionRows(
|
||||
rows: unknown,
|
||||
): number {
|
||||
): number | null {
|
||||
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 active = (row as { IsActive?: unknown }).IsActive;
|
||||
if (active === false || (active != null && Number(active) === 0)) continue;
|
||||
const caption = normalizeHullCaption(
|
||||
(row as { Caption?: unknown }).Caption,
|
||||
);
|
||||
@@ -102,13 +104,7 @@ export function authorityCulpritIdFromDetectionRows(
|
||||
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;
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Fallback AccidentCulpritId when parties inquiry is unavailable. */
|
||||
@@ -128,13 +124,12 @@ export function toFanavaranHullBaseClaimPayload(
|
||||
const next: Record<string, unknown> = {};
|
||||
for (const key of FANAVARAN_HULL_BASE_CLAIM_KEYS) {
|
||||
if (key === "IsLicenseReplaced") {
|
||||
// GEN.03: must be empty/null. Do not map ثالث IsLicenseReplacement (default 0).
|
||||
next[key] = null;
|
||||
// Hull GEN.03: explicitly send خیر. Keep the hull field name.
|
||||
next[key] = FANAVARAN_HULL_ANS_NO;
|
||||
continue;
|
||||
}
|
||||
if (key === "AccidentTypeId") {
|
||||
next[key] =
|
||||
built.AccidentTypeId ?? FANAVARAN_DEFAULT_HULL_ACCIDENT_TYPE_ID;
|
||||
next[key] = built.AccidentTypeId ?? null;
|
||||
continue;
|
||||
}
|
||||
if (key === "CostSeparationToDmgSections") {
|
||||
@@ -150,7 +145,7 @@ export function toFanavaranHullBaseClaimPayload(
|
||||
const raw = built.CulpritTypeId;
|
||||
// ثالث profile default 337 is not in vehicle-hull-accident-culprit-type.
|
||||
if (raw == null || raw === 337) {
|
||||
next[key] = FANAVARAN_DEFAULT_HULL_CULPRIT_TYPE_ID;
|
||||
next[key] = null;
|
||||
} else {
|
||||
next[key] = raw;
|
||||
}
|
||||
@@ -163,8 +158,12 @@ export function toFanavaranHullBaseClaimPayload(
|
||||
continue;
|
||||
}
|
||||
if (key === "AuthorityCulpritId") {
|
||||
next[key] =
|
||||
built.AuthorityCulpritId ?? FANAVARAN_DEFAULT_HULL_AUTHORITY_CULPRIT_ID;
|
||||
next[key] = built.AuthorityCulpritId ?? null;
|
||||
continue;
|
||||
}
|
||||
if (key === "PoliceOfficerId") {
|
||||
// The shared third-party builder supplies a sample 1; hull has no officer source.
|
||||
next[key] = null;
|
||||
continue;
|
||||
}
|
||||
next[key] = Object.prototype.hasOwnProperty.call(built, key)
|
||||
|
||||
Reference in New Issue
Block a user