forked from Yara724/api
car body implemented
This commit is contained in:
140
src/claim-request-management/fanavaran-hull-base-claim.ts
Normal file
140
src/claim-request-management/fanavaran-hull-base-claim.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
/** GEN.03 VHUD input fields. Do not send ثالث-only keys (DamagedCount, HasOtherCulprit, plaques, …). */
|
||||
export const FANAVARAN_HULL_BASE_CLAIM_KEYS = [
|
||||
"ArchiveNo",
|
||||
"AccidentDate",
|
||||
"AccidentTime",
|
||||
"AnnouncementDate",
|
||||
"AccidentLocationAddress",
|
||||
"ClaimExpertId",
|
||||
"EntryDate",
|
||||
"CulpritLicenceNo",
|
||||
"CulpritLicenceIssuDate",
|
||||
"CulpritLicenceForeignCityName",
|
||||
"PoliceReportSeri",
|
||||
"PoliceReportSerial",
|
||||
"PoliceReportDesc",
|
||||
"CustomerFaultPercent",
|
||||
"CulpritLevelTwoLicenceIssuDate",
|
||||
"ActualPremium",
|
||||
"EstimateAmount",
|
||||
"TrackingCode",
|
||||
"CourtArchiveNo",
|
||||
"PlaqueReplacementDate",
|
||||
"StatusChangeDate",
|
||||
"ClaimCompletionDate",
|
||||
"DmgAssessorFirstCreationTime",
|
||||
"PolicyId",
|
||||
"IsSurplusArticleEighthLaw",
|
||||
"AccidentCityId",
|
||||
"AccidentCauseId",
|
||||
"AccidentTypeId",
|
||||
"GlassBreakReasonId",
|
||||
"CulpritTypeId",
|
||||
"AuthorityCulpritId",
|
||||
"AccidentCulpritId",
|
||||
"CulpritLicenceTypeId",
|
||||
"IsLicenseReplaced",
|
||||
"CulpritLicenceCountryId",
|
||||
"CulpritLicenceCityId",
|
||||
"AccidentReportTypeId",
|
||||
"PoliceOfficerId",
|
||||
"IsAccidentOutOfBorder",
|
||||
"AccidentVehicleUsedId",
|
||||
"IsOwnerChanged",
|
||||
"CostSeparationToDmgSections",
|
||||
] as const;
|
||||
|
||||
/** GEN.03 default: تصادف(حادثه). Lookup: GET /lookups/vehicle-hull-accident-types */
|
||||
export const FANAVARAN_DEFAULT_HULL_ACCIDENT_TYPE_ID = 2;
|
||||
|
||||
/** 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 = 301;
|
||||
|
||||
/** GEN.03 ActualPremium from GET car/vehicle-hull-policies/{PolicyId} → TotalPremium. */
|
||||
export function actualPremiumFromHullPolicyRecord(
|
||||
policy: Record<string, unknown> | null | undefined,
|
||||
): number | null {
|
||||
if (!policy) return null;
|
||||
const raw = policy.TotalPremium ?? policy.totalPremium;
|
||||
const n = typeof raw === "number" ? raw : Number(raw);
|
||||
return Number.isFinite(n) && n >= 0 ? n : null;
|
||||
}
|
||||
|
||||
/** Fallback AccidentCulpritId when parties inquiry is unavailable. */
|
||||
export function customerIdFromHullPolicyRecord(
|
||||
policy: Record<string, unknown> | null | undefined,
|
||||
): number | null {
|
||||
if (!policy) return null;
|
||||
const raw = policy.CustomerId ?? policy.customerId;
|
||||
const n = typeof raw === "number" ? raw : Number(raw);
|
||||
return Number.isFinite(n) && n > 0 ? n : null;
|
||||
}
|
||||
|
||||
export function toFanavaranHullBaseClaimPayload(
|
||||
built: Record<string, unknown>,
|
||||
): Record<string, unknown> {
|
||||
const next: Record<string, unknown> = {};
|
||||
for (const key of FANAVARAN_HULL_BASE_CLAIM_KEYS) {
|
||||
if (key === "IsLicenseReplaced") {
|
||||
next[key] =
|
||||
built.IsLicenseReplaced ?? built.IsLicenseReplacement ?? null;
|
||||
continue;
|
||||
}
|
||||
if (key === "AccidentTypeId") {
|
||||
next[key] =
|
||||
built.AccidentTypeId ?? FANAVARAN_DEFAULT_HULL_ACCIDENT_TYPE_ID;
|
||||
continue;
|
||||
}
|
||||
if (key === "CostSeparationToDmgSections") {
|
||||
next[key] =
|
||||
built.CostSeparationToDmgSections ?? FANAVARAN_HULL_ANS_NO;
|
||||
continue;
|
||||
}
|
||||
if (key === "IsOwnerChanged") {
|
||||
next[key] = built.IsOwnerChanged ?? FANAVARAN_HULL_ANS_NO;
|
||||
continue;
|
||||
}
|
||||
if (key === "CulpritTypeId") {
|
||||
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;
|
||||
} else {
|
||||
next[key] = raw;
|
||||
}
|
||||
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;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
next[key] = Object.prototype.hasOwnProperty.call(built, key)
|
||||
? built[key]
|
||||
: null;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
/** Nested hull files/expertise use GEN.03 `Id` (کد رایانه), never `ClaimNo` (شماره پرونده). */
|
||||
export function fanavaranHullNestedClaimId(input: {
|
||||
Id?: unknown;
|
||||
ClaimNo?: unknown;
|
||||
claimId?: unknown;
|
||||
claimNo?: unknown;
|
||||
}): number | null {
|
||||
const id = input.claimId ?? input.Id;
|
||||
if (typeof id === "number" && Number.isFinite(id) && id > 0) return id;
|
||||
if (typeof id === "string" && /^\d+$/.test(id.trim())) return Number(id);
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user