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:
@@ -408,55 +408,13 @@ export function canReuseCachedFanavaranVehicleIds(source: unknown): boolean {
|
||||
export const FANAVARAN_NATIONAL_PLAQUE_KIND_ID = 8;
|
||||
export const FANAVARAN_NATIONAL_PLAQUE_SAMPLE_ID = 10;
|
||||
|
||||
export const FANAVARAN_DAMAGE_MANUAL_OVERRIDE_KEYS = [
|
||||
"Desc",
|
||||
"EstimateAmount",
|
||||
"LicenceNo",
|
||||
"LicenceIssuDate",
|
||||
"DriverIsOwner",
|
||||
] as const;
|
||||
|
||||
export const FANAVARAN_EXPERTISE_MANUAL_OVERRIDE_KEYS = [
|
||||
"RepairWage",
|
||||
"ComponentReplacementCost",
|
||||
"WasteValue",
|
||||
"DmgAssessmentDate",
|
||||
"InspectionTime",
|
||||
"DamagedVehicleCurrentPrice",
|
||||
"DropAmountAdditionsDeductions",
|
||||
] as const;
|
||||
|
||||
export const FANAVARAN_BASE_MANUAL_OVERRIDE_KEYS = [
|
||||
"EstimateAmount",
|
||||
"CulpritLicenceNo",
|
||||
"CulpritLicenceIssuDate",
|
||||
"AccidentLocationAddress",
|
||||
"AccidentDate",
|
||||
"AnnouncementDate",
|
||||
"DocReceivedDate",
|
||||
"AccidentTime",
|
||||
"PoliceReportDesc",
|
||||
"PoliceReportSeri",
|
||||
"PoliceReportSerial",
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* Swagger POST body is optional user-entry tweaks only.
|
||||
* Inquiry / lookup-filter ids always come from the live rebuilt payload.
|
||||
*/
|
||||
/** Supplied JSON fields win, including null, arrays, nested objects and lookup IDs. */
|
||||
export function applyFanavaranManualPayloadOverrides(
|
||||
built: Record<string, unknown>,
|
||||
body: Record<string, unknown> | null | undefined,
|
||||
keys: readonly string[],
|
||||
): Record<string, unknown> {
|
||||
if (!body) return built;
|
||||
const next = { ...built };
|
||||
for (const key of keys) {
|
||||
if (!Object.prototype.hasOwnProperty.call(body, key)) continue;
|
||||
if (body[key] === undefined) continue;
|
||||
next[key] = body[key];
|
||||
}
|
||||
return next;
|
||||
return { ...built, ...body };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user