forked from Yara724/api
fix(fanavaran): honor supplied submission payload fields
Apply every supplied JSON field over generated defaults, preserving IDs, nested values and explicit nulls across base, damage and expertise submits. Validate manual hull payloads without rewriting their values or premium, and derive an empty replacement flag for old hull licences.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { FanavaranClientKey } from "src/core/config/fanavaran-client.config";
|
||||
import { TEJARAT_NOTIFIER_FIELDS } from "src/fanavaran/tejarat-notifier";
|
||||
import { resolveFanavaranIsLicenseReplaced } from "./fanavaran-party-roles";
|
||||
import { isJalaliDateOlderThanYears } from "./fanavaran-party-roles";
|
||||
import { parseJalaliDateParts } from "./fanavaran-driver-inquiry";
|
||||
|
||||
/** GEN.03 VHUD input fields. Do not send ثالث-only keys (DamagedCount, HasOtherCulprit, plaques, …). */
|
||||
export const FANAVARAN_HULL_BASE_CLAIM_KEYS = [
|
||||
@@ -118,6 +119,17 @@ export function customerIdFromHullPolicyRecord(
|
||||
return Number.isFinite(n) && n > 0 ? n : null;
|
||||
}
|
||||
|
||||
/** Hull requires an empty replacement flag for licences older than three years. */
|
||||
export function resolveFanavaranHullIsLicenseReplaced(
|
||||
licenceIssuDate: unknown,
|
||||
accidentDate: unknown,
|
||||
): 0 | null {
|
||||
if (!parseJalaliDateParts(licenceIssuDate) || !parseJalaliDateParts(accidentDate)) {
|
||||
return null;
|
||||
}
|
||||
return isJalaliDateOlderThanYears(licenceIssuDate, accidentDate, 3) ? null : 0;
|
||||
}
|
||||
|
||||
export function toFanavaranHullBaseClaimPayload(
|
||||
built: Record<string, unknown>,
|
||||
clientKey?: FanavaranClientKey,
|
||||
@@ -125,14 +137,14 @@ export function toFanavaranHullBaseClaimPayload(
|
||||
const next: Record<string, unknown> = {};
|
||||
for (const key of FANAVARAN_HULL_BASE_CLAIM_KEYS) {
|
||||
if (key === "IsLicenseReplaced") {
|
||||
// Preserve the server's conditional 0 / null / 1 mapping for licence age.
|
||||
// Preserve explicit answers; otherwise derive the hull-specific default.
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(built, key) &&
|
||||
(built[key] === 1 || built[key] === 0 || built[key] === null)
|
||||
) {
|
||||
next[key] = built[key];
|
||||
} else {
|
||||
next[key] = resolveFanavaranIsLicenseReplaced(
|
||||
next[key] = resolveFanavaranHullIsLicenseReplaced(
|
||||
built.CulpritLicenceIssuDate,
|
||||
built.AccidentDate,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user