forked from Yara724/api
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61ef4faaf4 | ||
|
|
7bff702514 | ||
|
|
99e6fa0850 |
@@ -20,6 +20,15 @@ A PUT to `/vehicle-hull-claims/{Id}` may run before files/expertise; Parsian oft
|
||||
|
||||
**Send rule:** send the **hull whitelist only**. Do not send ثالث-only keys (`DamagedCount`, `HasOtherCulprit`, `CompensationReferenceId`, `DocReceivedDate`, `IsLicenseReplacement`, plaque block on base, …).
|
||||
|
||||
**Manual submit body:** every supplied top-level field overrides its generated
|
||||
value, including IDs, arrays, nested objects, `false`, `0` and JSON `null`.
|
||||
Omitted fields retain generated defaults. Arrays and nested objects replace the
|
||||
corresponding value; they are not merged element by element. Lookup validation
|
||||
checks a copy of manual payloads and does not refresh their supplied premium or
|
||||
rewrite their values. Automatic submission without overrides keeps its existing
|
||||
inquiry, normalization and validation behavior. This also applies to third-party
|
||||
base/damage submits and both products' expertise submits.
|
||||
|
||||
**Source tags:** same as `third-party-stage-fields.md` (`system` / `lookup` / `inquiry` / `user` / `staff` / `derived`).
|
||||
|
||||
---
|
||||
@@ -32,10 +41,11 @@ Built by `buildFanavaranSubmitPayload` then `enrichCarBodyHullBaseClaimPayload`
|
||||
`CustomerFaultPercent`, `AuthorityCulpritId`, `AccidentTypeId`, `CostSeparationToDmgSections`, `IsOwnerChanged`, `PolicyId`, `ClaimExpertId`, dates/time, `CulpritTypeId`.
|
||||
|
||||
**IsLicenseReplaced:** derived on the server from `CulpritLicenceIssuDate` and
|
||||
`AccidentDate`: `0` through the third anniversary, `null` after three years
|
||||
through the tenth anniversary, and `1` after ten years. Intake accepts valid past
|
||||
issue dates older than ten years; no expiry-date or replacement-checkbox input
|
||||
is required. The existing missing-date fallback is `1400/01/01`.
|
||||
`AccidentDate`: default `0` through the third anniversary and `null` afterward.
|
||||
Do not infer replacement from licence age exceeding ten years: Parsian rejects
|
||||
that `1` with «باید خالی باشد». The hull base-claim submit body may explicitly
|
||||
override `IsLicenseReplaced` with `0`, `1`, or JSON `null`; omitted fields keep
|
||||
the derived default. Intake accepts valid past issue dates older than ten years. The existing missing-date fallback is `1400/01/01`.
|
||||
|
||||
| Field | Persian | Type | Null? | Current value / source |
|
||||
|-------|---------|------|-------|------------------------|
|
||||
@@ -55,7 +65,7 @@ is required. The existing missing-date fallback is `1400/01/01`.
|
||||
| CustomerFaultPercent | درصد تقصیر بیمهگذار | number | **no** | **user** expert review, else **system** `100` |
|
||||
| CostSeparationToDmgSections | تفکیک هزینه به نقاط | number (ans) | **no** | **system** `0` خیر · lookup `ans` |
|
||||
| IsOwnerChanged | مالک تغییر یافته؟ | number (ans) | **no** | **system** `0` · lookup `ans` |
|
||||
| IsLicenseReplaced | گواهینامه تعویضی است؟ | number | often null | **derived** `1` if issue date >10y before accident, else `null` (hull name; ثالث uses `IsLicenseReplacement`) |
|
||||
| IsLicenseReplaced | گواهینامه تعویضی است؟ | number | often null | **derived** `0` through three years, otherwise `null`; explicit hull submit answer is preserved (ثالث uses `IsLicenseReplacement`) |
|
||||
| ActualPremium | حق بیمه واقعی | number | preferred | **inquiry** hull policy `TotalPremium` via `GET /lookups/body-policy/{PolicyId}` |
|
||||
| EstimateAmount | برآورد | number | **no** | **user** expert prices / provisional |
|
||||
| CulpritLicenceNo | شماره گواهینامه | string | **no** | dummy / **user** |
|
||||
@@ -142,9 +152,9 @@ Not ثالث GEN.08: no `DmgCaseId`, `InspectionPlaceId`, `RepairWage` on the ro
|
||||
| AccidentPercent | درصد حادثه | number | yes | null |
|
||||
| TheftCases | موارد سرقت | array | empty `[]` | system |
|
||||
| DmgSections[].Count | تعداد | number | **no** | **system** `1` |
|
||||
| DmgSections[].Desc | شرح قطعه | string | **no** | **user** part label |
|
||||
| DmgSections[].Desc | شرح قطعه | string | **no** | Saved expert-reply part label (`carPartDamage.label_fa`) |
|
||||
| DmgSections[].WasteValue | داغی ردیف | number | **no** | **user** |
|
||||
| DmgSections[].AccessoryKindId | نوع قطعه کاتالوگ | number | preferred | **user** `partId` · lookup `car-components` |
|
||||
| DmgSections[].AccessoryKindId | نوع قطعه کاتالوگ | number | preferred | Saved `evaluation.damageExpertReply.parts[].partId`, passed through directly; policy matching and factory bundles must never replace it |
|
||||
| DmgSections[].DmgKindId | نوع آسیب بدنه | number | **no** | Current `vehicle-hull-dmg-kind` API row caption تخریب; no numeric fallback |
|
||||
| DmgSections[].VehicleHullAccessoryId | شناسه لوازم بدنه | number | preferred | Current policy `dmg-accessories`: exact `AccessoryKindId` or caption match; else the «کليه قطعات فابريک» factory-bundle row `Id`. Keep selected car-components `AccessoryKindId` + part `Desc` |
|
||||
| DmgSections[].DmgSectionCosts[].Caption | عنوان هزینه | string | **no** | **user** label |
|
||||
|
||||
@@ -831,15 +831,23 @@
|
||||
<select id="DRIVER_IS_OWNER"><option value="1" selected>1</option><option value="0">0</option></select>
|
||||
</label>
|
||||
</div>
|
||||
<p class="hint">اگر این شخص در فناوران نیست، موبایل و بقیه مشخصات ثبت را در تب «ثبت شخص» وارد کنید. همان مقادیر در GEN.44 فرستاده میشود.</p>
|
||||
<p class="hint">اگر این شخص در فناوران نیست یا برای بدنه نقش «سایر» ندارد، مشخصات او را در تب «ثبت شخص» وارد کنید.</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div class="tab-panel" data-form-panel="person" hidden>
|
||||
<section class="card">
|
||||
<h2><span class="n">+</span> ثبت شخص — GEN.44</h2>
|
||||
<p class="hint">وقتی استعلام نقش ۱۶۱ یا ۱۶۶ خالی است، این فیلدها در POST سایر اشخاص میروند. خالی یا کلمه null یعنی JSON null. موبایل برای این تنانت اجباری است.</p>
|
||||
<p class="hint">برای بدنه، شخص باید نقش «سایر» (۱۶۶) داشته باشد؛ نقش بیمهگذار (۱۶۱) بهتنهایی کافی نیست. مشخصات همین فرم برای ثبت شخص استفاده میشود. خالی یا کلمه null یعنی JSON null. موبایل برای این تنانت اجباری است.</p>
|
||||
<div class="grid 3">
|
||||
<label class="s3"><b>نقش مورد نظر برای ثبت</b>
|
||||
<select id="PERSON_ROLE_ID" required>
|
||||
<option value="">— نقش را انتخاب کنید —</option>
|
||||
<option value="166">سایر — 166 (برای ثبت راننده)</option>
|
||||
<option value="161" disabled>بیمهگذار — 161 (در این سرویس قابل ثبت نیست)</option>
|
||||
</select>
|
||||
<span class="hint">این فرم نقش «سایر» را با سرویس ثبت سایر اشخاص اضافه میکند. نقشهای قبلی شخص حفظ میشوند.</span>
|
||||
</label>
|
||||
<label><b>کد ملی</b><input id="personNc" value="0017819199" maxlength="10" /></label>
|
||||
<label><b>تاریخ تولد</b><input id="personBd" value="13731228" placeholder="YYYYMMDD" /></label>
|
||||
<label><b>موبایل</b><input id="DRIVER_MOBILE" placeholder="0912…" dir="ltr" /></label>
|
||||
@@ -1684,6 +1692,7 @@ node scripts/fanavaran-flow-ui-server.js</pre>
|
||||
DRIVER_BIRTH_DAY:bd.d,
|
||||
DRIVER_IS_INSURER:q("DRIVER_IS_INSURER"),
|
||||
DRIVER_IS_OWNER:q("DRIVER_IS_OWNER"),
|
||||
PERSON_ROLE_ID:q("PERSON_ROLE_ID"),
|
||||
DRIVER_MOBILE:q("DRIVER_MOBILE"),
|
||||
DRIVER_TEL:q("DRIVER_TEL"),
|
||||
DRIVER_ADDRESS:q("DRIVER_ADDRESS"),
|
||||
@@ -1819,12 +1828,11 @@ node scripts/fanavaran-flow-ui-server.js</pre>
|
||||
$("EXPERTISE_CLAIM_EXPERT_ID").closest("label").querySelector("b").textContent = hull ? "GEN.06 ClaimExpertId" : "GEN.08 ExpertiseClaimExpertId";
|
||||
$("stageNotification").hidden = hull || q("FANAVARAN_API_VERSION") !== "v15";
|
||||
$("formTabNotify").hidden = hull || (q("FANAVARAN_API_VERSION") !== "v15" && q("FANAVARAN_CLIENT") !== "moallem");
|
||||
document.querySelector('[data-form-panel="person"]').hidden = hull;
|
||||
document.querySelector('[data-form-tab="person"]').hidden = hull;
|
||||
if (hull && document.querySelector('[data-form-tab="person"]')?.classList.contains("active")) showFormTab("cars");
|
||||
document.querySelector('[data-form-tab="person"]').hidden = false;
|
||||
}
|
||||
|
||||
function missingRequiredNotifier(stage) {
|
||||
if (stage === "auth" || stage === "person") return "";
|
||||
if (q("FANAVARAN_PRODUCT") === "CAR_BODY") return "";
|
||||
const v15 = q("FANAVARAN_API_VERSION") === "v15";
|
||||
const moallemV14 = q("FANAVARAN_CLIENT") === "moallem" && !v15;
|
||||
@@ -2025,6 +2033,7 @@ node scripts/fanavaran-flow-ui-server.js</pre>
|
||||
}
|
||||
set("DRIVER_IS_INSURER","DRIVER_IS_INSURER");
|
||||
set("DRIVER_IS_OWNER","DRIVER_IS_OWNER");
|
||||
set("PERSON_ROLE_ID","PERSON_ROLE_ID");
|
||||
set("DRIVER_MOBILE","DRIVER_MOBILE");
|
||||
set("DRIVER_TEL","DRIVER_TEL");
|
||||
set("DRIVER_ADDRESS","DRIVER_ADDRESS");
|
||||
@@ -2323,6 +2332,12 @@ node scripts/fanavaran-flow-ui-server.js</pre>
|
||||
setStatus("سرور UI روشن نیست.", "err");
|
||||
return;
|
||||
}
|
||||
if (stage === "person" && q("PERSON_ROLE_ID") !== "166") {
|
||||
setStatus("نقش مورد نظر را انتخاب کنید. این فرم ثبت نقش سایر (166) را پشتیبانی میکند.", "err");
|
||||
showFormTab("person");
|
||||
$("PERSON_ROLE_ID").focus();
|
||||
return;
|
||||
}
|
||||
if (q("FANAVARAN_PRODUCT") !== "CAR_BODY" && q("CULPRIT_TYPE_ID")==="338" && !q("ACCIDENT_CULPRIT_ID") && (stage==="base"||stage==="all")) {
|
||||
setStatus("ACCIDENT_CULPRIT_ID برای CulpritTypeId=338 لازم است.", "err");
|
||||
return;
|
||||
@@ -2408,6 +2423,11 @@ node scripts/fanavaran-flow-ui-server.js</pre>
|
||||
body: JSON.stringify({ stage, env, ui: collectUi() }),
|
||||
});
|
||||
if (result.ids) Object.assign(stateIds, result.ids);
|
||||
if (result.ok && stage === "person" && q("FANAVARAN_PRODUCT") === "CAR_BODY" && result.ids?.ACCIDENT_CULPRIT_ID) {
|
||||
setComboValue("ACCIDENT_CULPRIT_ID", result.ids.ACCIDENT_CULPRIT_ID, {
|
||||
id: result.ids.ACCIDENT_CULPRIT_ID, caption: "راننده ثبتشده با نقش سایر",
|
||||
});
|
||||
}
|
||||
renderIds();
|
||||
const snap = snapshot();
|
||||
persistLocal(snap);
|
||||
|
||||
@@ -812,7 +812,8 @@ inquire_hull_policy_vehicle() {
|
||||
}
|
||||
|
||||
inquire_driver_id() {
|
||||
if [[ -n "${DRIVER_ID:-}" ]]; then
|
||||
local required_role="${1:-}"
|
||||
if [[ -n "${DRIVER_ID:-}" && "$required_role" != "166" ]] && ! is_car_body; then
|
||||
ok "Using DRIVER_ID=$DRIVER_ID from env (skip inquiry)"
|
||||
return 0
|
||||
fi
|
||||
@@ -830,14 +831,14 @@ inquire_driver_id() {
|
||||
fv_curl_json GET "$url" "$out"
|
||||
|
||||
local target_role=166
|
||||
if [[ "$DRIVER_IS_INSURER" == "1" || "${DRIVER_IS_INSURER,,}" == "true" ]]; then
|
||||
if [[ "$required_role" != "166" ]] && ! is_car_body && [[ "$DRIVER_IS_INSURER" == "1" || "${DRIVER_IS_INSURER,,}" == "true" ]]; then
|
||||
target_role=161
|
||||
fi
|
||||
|
||||
DRIVER_ID="$(node -e '
|
||||
const fs = require("fs");
|
||||
const target = Number(process.argv[2]);
|
||||
const ACCEPTED = new Set([161, 166]);
|
||||
const ACCEPTED = new Set(process.argv[3] === "CAR_BODY" || process.argv[4] === "166" ? [166] : [161, 166]);
|
||||
const data = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
||||
const rows = Array.isArray(data) ? data : (data?.value || data?.data || []);
|
||||
if (!Array.isArray(rows) || !rows.length) { console.log(""); process.exit(0); }
|
||||
@@ -846,20 +847,21 @@ if (match && Number(match.Id) > 0) { console.log(String(match.Id)); process.exit
|
||||
const accepted = rows.find(r => ACCEPTED.has(Number(r.RoleId)) && Number(r.Id) > 0);
|
||||
if (accepted) console.log(String(accepted.Id));
|
||||
else console.log("");
|
||||
' "$out" "$target_role")"
|
||||
' "$out" "$target_role" "$FANAVARAN_PRODUCT" "$required_role")"
|
||||
|
||||
if [[ -n "$DRIVER_ID" ]]; then
|
||||
ok "DriverId=$DRIVER_ID (inquiry RoleId=$target_role or accepted 161/166)"
|
||||
ok "DriverId=$DRIVER_ID (verified acceptable role; target RoleId=$target_role)"
|
||||
persist_env DRIVER_ID
|
||||
save_ids
|
||||
return 0
|
||||
fi
|
||||
|
||||
warn "Driver inquiry has no RoleId 161/166 for $DRIVER_NATIONAL_CODE — GEN.44 other-people create"
|
||||
create_other_person
|
||||
warn "Driver inquiry has no acceptable role for $DRIVER_NATIONAL_CODE — GEN.44 other-people create"
|
||||
create_other_person "$required_role"
|
||||
}
|
||||
|
||||
create_other_person() {
|
||||
local required_role="${1:-}"
|
||||
require_var DRIVER_NATIONAL_CODE
|
||||
require_var DRIVER_BIRTH_YEAR
|
||||
require_var DRIVER_BIRTH_MONTH
|
||||
@@ -956,7 +958,7 @@ NODE
|
||||
|
||||
DRIVER_ID="$(node -e '
|
||||
const fs = require("fs");
|
||||
const ACCEPTED = new Set([161, 166]);
|
||||
const ACCEPTED = new Set(process.argv[2] === "CAR_BODY" || process.argv[3] === "166" ? [166] : [161, 166]);
|
||||
const data = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
||||
const rows = Array.isArray(data) ? data : (data?.value || data?.data || []);
|
||||
const accepted = Array.isArray(rows)
|
||||
@@ -964,9 +966,9 @@ const accepted = Array.isArray(rows)
|
||||
: null;
|
||||
if (accepted) console.log(String(accepted.Id));
|
||||
else console.log("");
|
||||
' "$retry")"
|
||||
' "$retry" "$FANAVARAN_PRODUCT" "$required_role")"
|
||||
|
||||
if [[ -z "$DRIVER_ID" && -n "${OTHER_PERSON_ID:-}" ]]; then
|
||||
if [[ -z "$DRIVER_ID" && -n "${OTHER_PERSON_ID:-}" && "$required_role" != "166" ]] && ! is_car_body; then
|
||||
DRIVER_ID="$OTHER_PERSON_ID"
|
||||
warn "Re-inquiry still empty — using GEN.44 Id as DriverId=$DRIVER_ID"
|
||||
fi
|
||||
@@ -1644,10 +1646,20 @@ info "Fanavaran-only flow | client=$FANAVARAN_CLIENT | api=$API_VERSION_LABEL |
|
||||
info "Env file (section B will be updated in-place): $ENV_FILE"
|
||||
info "Output: $OUT_DIR"
|
||||
|
||||
if stage_wanted person; then
|
||||
[[ "${PERSON_ROLE_ID:-}" == "166" ]] || die "Select PERSON_ROLE_ID=166 (سایر). GEN.44 does not register arbitrary roles."
|
||||
fi
|
||||
|
||||
fanavaran_login
|
||||
|
||||
if stage_wanted person && ! is_car_body; then
|
||||
inquire_driver_id
|
||||
if stage_wanted person; then
|
||||
info "Person registration requested: RoleId=$PERSON_ROLE_ID (سایر); checking live inquiry"
|
||||
inquire_driver_id "$PERSON_ROLE_ID"
|
||||
if is_car_body && [[ -n "${DRIVER_ID:-}" && "$PREVIEW_ONLY" -eq 0 ]]; then
|
||||
ACCIDENT_CULPRIT_ID="$DRIVER_ID"
|
||||
persist_env ACCIDENT_CULPRIT_ID
|
||||
save_ids
|
||||
fi
|
||||
fi
|
||||
|
||||
# Soft-ensure order like the app: later stages create earlier ones if ids missing
|
||||
|
||||
@@ -786,6 +786,7 @@ function envObjectToText(obj) {
|
||||
"DRIVER_BIRTH_DAY",
|
||||
"DRIVER_IS_INSURER",
|
||||
"DRIVER_IS_OWNER",
|
||||
"PERSON_ROLE_ID",
|
||||
"DRIVER_MOBILE",
|
||||
"DRIVER_TEL",
|
||||
"DRIVER_ADDRESS",
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const vm = require("node:vm");
|
||||
const { test } = require("node:test");
|
||||
const { spawnSync } = require("node:child_process");
|
||||
const html = fs.readFileSync(path.join(__dirname, "data/fanavaran-flow-ui.html"), "utf8");
|
||||
const shell = fs.readFileSync(path.join(__dirname, "fanavaran-flow-test.sh"), "utf8");
|
||||
|
||||
test("hull selection keeps the registration tab visible and preserves an open registration panel", () => {
|
||||
const tab = { hidden: true, classList: { contains: () => true } };
|
||||
const panel = { hidden: false };
|
||||
const element = { closest: () => ({ querySelector: () => ({}) }) };
|
||||
const context = vm.createContext({
|
||||
q: (id) => id === "FANAVARAN_PRODUCT" ? "CAR_BODY" : "v14",
|
||||
$: () => element,
|
||||
showFormTab: () => assert.fail("switching product must not eject the person tab"),
|
||||
document: {
|
||||
body: { dataset: {} },
|
||||
querySelector: (selector) => selector.includes('panel="person"') ? panel : tab,
|
||||
},
|
||||
});
|
||||
const start = html.indexOf(" function syncProduct()");
|
||||
const end = html.indexOf(" function missingRequiredNotifier", start);
|
||||
vm.runInContext(html.slice(start, end) + "\nsyncProduct();", context);
|
||||
assert.equal(tab.hidden, false);
|
||||
assert.equal(panel.hidden, false);
|
||||
});
|
||||
|
||||
function selectDriver(product, rows, afterCreate = false, requiredRole = "") {
|
||||
const start = shell.indexOf(' DRIVER_ID="$(node -e \'', shell.indexOf(afterCreate ? "create_other_person() {" : "inquire_driver_id() {"));
|
||||
const bodyStart = shell.indexOf("\n", start) + 1;
|
||||
const end = shell.indexOf("\n' ", bodyStart);
|
||||
let selected = "";
|
||||
const exited = {};
|
||||
const context = vm.createContext({
|
||||
require: () => ({ readFileSync: () => JSON.stringify(rows) }),
|
||||
process: { argv: afterCreate ? ["node", "fixture", product, requiredRole] : ["node", "fixture", "166", product, requiredRole], exit: () => { throw exited; } },
|
||||
console: { log: (value) => { selected = String(value); } },
|
||||
});
|
||||
try { vm.runInContext(shell.slice(bodyStart, end), context); }
|
||||
catch (error) { if (error !== exited) throw error; }
|
||||
return selected;
|
||||
}
|
||||
|
||||
for (const afterCreate of [false, true]) {
|
||||
test(`hull ${afterCreate ? "post-registration verification" : "inquiry"} requires role 166`, () => {
|
||||
assert.equal(selectDriver("CAR_BODY", [{ Id: 41, RoleId: 161 }], afterCreate), "");
|
||||
assert.equal(selectDriver("CAR_BODY", [{ Id: 41, RoleId: 161 }, { Id: 42, RoleId: 166 }], afterCreate), "42");
|
||||
});
|
||||
test(`third-party ${afterCreate ? "verification" : "inquiry"} retains role-161 acceptance`, () => {
|
||||
assert.equal(selectDriver("THIRD_PARTY", [{ Id: 41, RoleId: 161 }], afterCreate), "41");
|
||||
});
|
||||
}
|
||||
|
||||
test("the inline UI script parses", () => {
|
||||
const script = html.match(/<script>([\s\S]*?)<\/script>/)[1];
|
||||
new vm.Script(script);
|
||||
});
|
||||
|
||||
for (const [client, version] of [["moallem", "v14"], ["tejaratno", "v15"]]) {
|
||||
test(`${client} ${version}: registering a person does not require claim notifier fields`, () => {
|
||||
const context = vm.createContext({
|
||||
q: (id) => ({ FANAVARAN_PRODUCT: "THIRD_PARTY", FANAVARAN_CLIENT: client,
|
||||
FANAVARAN_API_VERSION: version, CLAIM_NOTIFICATION_DATE: "1405/08/30",
|
||||
NOTIFIER_PARTY_ID: "41" })[id] || "",
|
||||
lookupValue: () => "",
|
||||
stateIds: { CLAIM_ID: "" },
|
||||
});
|
||||
const start = html.indexOf(" function missingRequiredNotifier(stage)");
|
||||
const end = html.indexOf(" function envToText", start);
|
||||
vm.runInContext(html.slice(start, end), context);
|
||||
assert.equal(vm.runInContext('missingRequiredNotifier("person")', context), "");
|
||||
assert.match(vm.runInContext('missingRequiredNotifier("base")', context), /NotifierTypeId/);
|
||||
assert.match(vm.runInContext('missingRequiredNotifier("base")', context), /NotifierRelationId/);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
for (const afterCreate of [false, true]) {
|
||||
test(`manual person ${afterCreate ? "verification" : "inquiry"} enforces the selected role even in third-party mode`, () => {
|
||||
assert.equal(selectDriver("THIRD_PARTY", [{ Id: 41, RoleId: 161 }], afterCreate, "166"), "");
|
||||
assert.equal(selectDriver("THIRD_PARTY", [{ Id: 41, RoleId: 161 }, { Id: 42, RoleId: 166 }], afterCreate, "166"), "42");
|
||||
});
|
||||
}
|
||||
|
||||
test("manual role-166 registration checks live inquiry despite a cached driver ID", () => {
|
||||
const start = shell.indexOf("inquire_driver_id() {");
|
||||
const end = shell.indexOf("create_other_person() {", start);
|
||||
const script = `set -euo pipefail
|
||||
${shell.slice(start, end)}
|
||||
is_car_body() { return 1; }
|
||||
ask_var() { :; }
|
||||
info() { :; }
|
||||
ok() { :; }
|
||||
warn() { :; }
|
||||
persist_env() { :; }
|
||||
save_ids() { :; }
|
||||
fv_curl_json() { echo LIVE_INQUIRY; }
|
||||
node() { printf 42; }
|
||||
create_other_person() { echo UNEXPECTED_CREATE; }
|
||||
DRIVER_ID=41
|
||||
DRIVER_IS_INSURER=1
|
||||
DRIVER_NATIONAL_CODE=0012345678
|
||||
DRIVER_BIRTH_YEAR=1360
|
||||
DRIVER_BIRTH_MONTH=1
|
||||
DRIVER_BIRTH_DAY=2
|
||||
FANAVARAN_PRODUCT=THIRD_PARTY
|
||||
FANAVARAN_BIME_URL=https://example.invalid
|
||||
OUT_DIR=/tmp
|
||||
inquire_driver_id 166
|
||||
printf 'RESULT=%s' "$DRIVER_ID"
|
||||
`;
|
||||
const result = spawnSync("/bin/bash", ["-c", script], { encoding: "utf8", timeout: 5000 });
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.match(result.stdout, /LIVE_INQUIRY/);
|
||||
assert.match(result.stdout, /RESULT=42/);
|
||||
assert.doesNotMatch(result.stdout, /UNEXPECTED_CREATE/);
|
||||
});
|
||||
|
||||
test("the registration button requires an explicit supported role before sending a request", async () => {
|
||||
const notices = [];
|
||||
let focused = false;
|
||||
const context = vm.createContext({
|
||||
busy: false,
|
||||
ping: async () => true,
|
||||
q: () => "",
|
||||
setStatus: (message) => notices.push(message),
|
||||
showFormTab: (name) => assert.equal(name, "person"),
|
||||
$: (id) => { assert.equal(id, "PERSON_ROLE_ID"); return { focus: () => { focused = true; } }; },
|
||||
api: () => assert.fail("registration cannot run before role selection"),
|
||||
});
|
||||
const start = html.indexOf(" async function runStage(stage)");
|
||||
const end = html.indexOf(' $("LOCATION").addEventListener', start);
|
||||
vm.runInContext(html.slice(start, end), context);
|
||||
await vm.runInContext('runStage("person")', context);
|
||||
assert.equal(focused, true);
|
||||
assert.match(notices[0], /166/);
|
||||
});
|
||||
@@ -198,6 +198,7 @@ import {
|
||||
FANAVARAN_DEFAULT_HULL_CUSTOMER_FAULT_PERCENT,
|
||||
fanavaranHullNestedClaimId,
|
||||
toFanavaranHullBaseClaimPayload,
|
||||
resolveFanavaranHullIsLicenseReplaced,
|
||||
} from './fanavaran-hull-base-claim';
|
||||
import { toTejaratV15ThirdPartyBasePayload } from './fanavaran-v15-third-party-base';
|
||||
import {
|
||||
@@ -213,7 +214,6 @@ import {
|
||||
import {
|
||||
FANAVARAN_HULL_DMG_COST_KIND_CAPTION,
|
||||
FANAVARAN_HULL_DMG_KIND_CAPTION,
|
||||
findLookupCaptionById,
|
||||
findLookupIdByCaption,
|
||||
findHullFactoryBundleAccessory,
|
||||
asHullDmgAccessoryRows,
|
||||
@@ -268,9 +268,6 @@ import {
|
||||
asVehicleInquiryRows,
|
||||
collectPartyVinCandidates,
|
||||
completePlaqueParts,
|
||||
FANAVARAN_BASE_MANUAL_OVERRIDE_KEYS,
|
||||
FANAVARAN_DAMAGE_MANUAL_OVERRIDE_KEYS,
|
||||
FANAVARAN_EXPERTISE_MANUAL_OVERRIDE_KEYS,
|
||||
fanavaranVehicleMatchesDamagedIdentity,
|
||||
normalizeVin,
|
||||
parseFanavaranId,
|
||||
@@ -2739,7 +2736,7 @@ export class ClaimRequestManagementService {
|
||||
);
|
||||
input.payload.CulpritLicenceIssuDate =
|
||||
resolveFanavaranLicenceIssuDate(driverIdentity);
|
||||
const licenseReplaced = resolveFanavaranIsLicenseReplaced(
|
||||
const licenseReplaced = resolveFanavaranHullIsLicenseReplaced(
|
||||
input.payload.CulpritLicenceIssuDate,
|
||||
input.payload.AccidentDate,
|
||||
);
|
||||
@@ -2850,6 +2847,7 @@ export class ClaimRequestManagementService {
|
||||
contractOptions,
|
||||
)
|
||||
: Promise.resolve(null),
|
||||
// Validate saved part IDs against the catalogue without remapping them.
|
||||
input.parts.length ? this.getFanavaranLookupRows(input.clientKey, 'car-components', true) : Promise.resolve([]),
|
||||
]);
|
||||
|
||||
@@ -2938,29 +2936,19 @@ export class ClaimRequestManagementService {
|
||||
const factoryBundle = findHullFactoryBundleAccessory(accessories);
|
||||
const hullSections = input.parts.map((part: any, index: number) => {
|
||||
const partKindId = parseFanavaranId(part?.partId);
|
||||
// Prefer live car-components Caption so Desc matches the frontend catalogue.
|
||||
const catalogueCaption = findLookupCaptionById(componentRows, partKindId);
|
||||
const localLabel = this.fanavaranPartLabel(part);
|
||||
const partLabel = catalogueCaption || localLabel;
|
||||
// The saved expert reply already identifies the selected catalogue part.
|
||||
const partLabel = this.fanavaranPartLabel(part);
|
||||
const resolved = resolveHullDmgSectionAccessory(
|
||||
accessories,
|
||||
partKindId,
|
||||
partLabel,
|
||||
);
|
||||
// No per-part policy row → cover under «کليه قطعات فابريک» Id (e.g. 3061139).
|
||||
// Use the bundle's own AccessoryKindId (e.g. 112) so Fanavaran receives a
|
||||
// coherent Id/AccessoryKindId pair from the policy row.
|
||||
// Policy coverage is resolved separately from the assessed part identity.
|
||||
let vehicleHullAccessoryId = resolved?.vehicleHullAccessoryId ?? null;
|
||||
let accessoryKindId: number | string | null | undefined =
|
||||
resolved?.accessoryKindId ?? part?.partId;
|
||||
if (!resolved && factoryBundle) {
|
||||
vehicleHullAccessoryId = factoryBundle.vehicleHullAccessoryId;
|
||||
// Replace the unrecognised per-part AccessoryKindId with the bundle's own
|
||||
// kind (e.g. 112 = «کليه قطعات فابريک»). Fanavaran requires Id and
|
||||
// AccessoryKindId to come from the same policy dmg-accessories row.
|
||||
accessoryKindId = factoryBundle.accessoryKindId ?? accessoryKindId;
|
||||
input.infoWarnings.push(
|
||||
`DmgSections[${index}] (${partLabel || part?.partId || 'part'}): AccessoryKindId=${part?.partId ?? '(missing)'} is a fabrique part (no separate policy row); mapped to factory bundle VehicleHullAccessoryId=${factoryBundle.vehicleHullAccessoryId} AccessoryKindId=${accessoryKindId} («کليه قطعات فابريک»).`,
|
||||
`DmgSections[${index}] (${partLabel || part?.partId || 'part'}): AccessoryKindId=${part?.partId ?? '(missing)'} is a fabrique part (no separate policy row); mapped to factory bundle VehicleHullAccessoryId=${factoryBundle.vehicleHullAccessoryId}; preserving AccessoryKindId=${partKindId} («کليه قطعات فابريک»).`,
|
||||
);
|
||||
} else if (!resolved) {
|
||||
input.warnings.push(
|
||||
@@ -2968,7 +2956,7 @@ export class ClaimRequestManagementService {
|
||||
);
|
||||
}
|
||||
return toFanavaranHullExpertiseDmgSection({
|
||||
partId: accessoryKindId,
|
||||
partId: partKindId,
|
||||
desc: partLabel,
|
||||
wasteValue: this.fanavaranDaghiWasteValue(part?.daghi),
|
||||
amount:
|
||||
@@ -4642,6 +4630,8 @@ export class ClaimRequestManagementService {
|
||||
requirePolicyId?: boolean;
|
||||
/** Only submission may register the hull driver through GEN.44. */
|
||||
registerMissingHullDriver?: boolean;
|
||||
/** Internal manual-submit default source; the final body retains its exact value. */
|
||||
policyIdOverride?: unknown;
|
||||
/**
|
||||
* When false (HTTP preview), missing staff ClaimExpertId stays null and is
|
||||
* reported in previewWarnings instead of throwing.
|
||||
@@ -4792,6 +4782,11 @@ export class ClaimRequestManagementService {
|
||||
logPrefix,
|
||||
requirePolicyId,
|
||||
resolvePolicyId: async () => {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(options ?? {}, 'policyIdOverride')
|
||||
) {
|
||||
return options.policyIdOverride as number;
|
||||
}
|
||||
const product = fanavaranClaimProductFromBlameType(blameCase.type);
|
||||
|
||||
if (cachedPolicyId != null && !forceRefreshPolicy) {
|
||||
@@ -6086,8 +6081,10 @@ export class ClaimRequestManagementService {
|
||||
payload: Record<string, unknown>,
|
||||
clientKey: FanavaranClientKey,
|
||||
claimCaseId?: string,
|
||||
preservePayload = false,
|
||||
): Promise<void> {
|
||||
if (!/\/car\/vehicle-hull-claims(?:\/|$)/.test(url)) return;
|
||||
if (preservePayload) payload = JSON.parse(JSON.stringify(payload));
|
||||
const stage: HullLookupStage = url.endsWith('/expertise')
|
||||
? 'expertise'
|
||||
: url.endsWith('/files') ? 'files' : 'baseClaim';
|
||||
@@ -6108,7 +6105,7 @@ export class ClaimRequestManagementService {
|
||||
);
|
||||
},
|
||||
);
|
||||
if (stage === 'baseClaim') {
|
||||
if (stage === 'baseClaim' && !preservePayload) {
|
||||
const policyId = parseFanavaranId(payload.PolicyId);
|
||||
try {
|
||||
const policy = policyId == null ? null : asObjectRecord(
|
||||
@@ -6543,6 +6540,8 @@ export class ClaimRequestManagementService {
|
||||
bodyOverride?: Record<string, unknown>,
|
||||
): Promise<any> {
|
||||
try {
|
||||
const manualSubmission =
|
||||
bodyOverride != null && Object.keys(bodyOverride).length > 0;
|
||||
await this.completeFanavaranExpertisePrerequisites(
|
||||
claimCaseId,
|
||||
clientKey,
|
||||
@@ -6557,20 +6556,23 @@ export class ClaimRequestManagementService {
|
||||
const built = await this.buildFanavaranExpertisePayload({
|
||||
claimCase,
|
||||
clientKey,
|
||||
requireClaimExpertId: !manualSubmission,
|
||||
});
|
||||
const payload = applyFanavaranManualPayloadOverrides(
|
||||
built.payload,
|
||||
bodyOverride,
|
||||
FANAVARAN_EXPERTISE_MANUAL_OVERRIDE_KEYS,
|
||||
);
|
||||
this.assertFanavaranExpertisePayloadReady(payload, built.warnings, {
|
||||
...hullExpertiseAssertFields(product),
|
||||
});
|
||||
this.assertFanavaranExpertisePayloadReady(
|
||||
payload,
|
||||
manualSubmission ? [] : built.warnings,
|
||||
{ ...hullExpertiseAssertFields(product) },
|
||||
);
|
||||
const result = await this.executeFanavaranExpertiseSubmit(
|
||||
claimCaseId,
|
||||
clientKey,
|
||||
payload,
|
||||
FanavaranAuditSource.SUBMIT,
|
||||
manualSubmission,
|
||||
);
|
||||
// Surface infoWarnings (e.g. factory-bundle fallbacks) on the success
|
||||
// response so callers are informed, without ever blocking the submit.
|
||||
@@ -6593,6 +6595,7 @@ export class ClaimRequestManagementService {
|
||||
clientKey: FanavaranClientKey,
|
||||
payload: Record<string, unknown>,
|
||||
auditSource: FanavaranAuditSource,
|
||||
preservePayload = false,
|
||||
): Promise<any> {
|
||||
let claimCase = await this.claimCaseDbService.findById(claimCaseId);
|
||||
if (!claimCase) throw new NotFoundException('Claim case not found');
|
||||
@@ -6659,6 +6662,8 @@ export class ClaimRequestManagementService {
|
||||
payload,
|
||||
clientKey,
|
||||
auditSession,
|
||||
claimCaseId,
|
||||
preservePayload,
|
||||
);
|
||||
const expertiseId = response.data?.Id;
|
||||
const exchange =
|
||||
@@ -7024,9 +7029,16 @@ export class ClaimRequestManagementService {
|
||||
clientKey: FanavaranClientKey,
|
||||
auditSession?: FanavaranAuditSession,
|
||||
claimCaseId?: string,
|
||||
preservePayload = false,
|
||||
) {
|
||||
this.fanavaranAuthService.assertNotInBackoff(clientKey);
|
||||
await this.assertFanavaranHullApiValues(url, payload, clientKey, claimCaseId ?? auditSession?.claimCaseId);
|
||||
await this.assertFanavaranHullApiValues(
|
||||
url,
|
||||
payload,
|
||||
clientKey,
|
||||
claimCaseId ?? auditSession?.claimCaseId,
|
||||
preservePayload,
|
||||
);
|
||||
const headers = await this.getFanavaranAuthHeaders(
|
||||
clientKey,
|
||||
auditSession,
|
||||
@@ -7365,18 +7377,19 @@ export class ClaimRequestManagementService {
|
||||
selectedParts: selectedParts ?? claimCase.damage?.selectedParts ?? [],
|
||||
clientKey,
|
||||
defaults: profile.defaults,
|
||||
registerMissingPerson: true,
|
||||
registerMissingPerson:
|
||||
bodyOverride == null || Object.keys(bodyOverride).length === 0,
|
||||
});
|
||||
const payload = applyFanavaranManualPayloadOverrides(
|
||||
builtPayload,
|
||||
bodyOverride,
|
||||
FANAVARAN_DAMAGE_MANUAL_OVERRIDE_KEYS,
|
||||
);
|
||||
|
||||
// Guardrail: never send empty/null licence fields even if manual overrides arrive.
|
||||
payload.LicenceNo = this.ensureFanavaranNonEmptyLicenceNo(
|
||||
payload.LicenceNo,
|
||||
);
|
||||
if (!Object.prototype.hasOwnProperty.call(bodyOverride ?? {}, 'LicenceNo')) {
|
||||
payload.LicenceNo = this.ensureFanavaranNonEmptyLicenceNo(
|
||||
payload.LicenceNo,
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.log(
|
||||
`[executeFanavaranDamageCaseSubmit] claimCaseId=${claimCaseId} claimId=${claimCase.claimId} payload.DriverId=${payload.DriverId ?? 'NULL'} payload keys=${Object.keys(payload).join(', ')}`,
|
||||
@@ -7405,6 +7418,8 @@ export class ClaimRequestManagementService {
|
||||
payload,
|
||||
clientKey,
|
||||
auditSession,
|
||||
claimCaseId,
|
||||
bodyOverride != null && Object.keys(bodyOverride).length > 0,
|
||||
);
|
||||
const dmgCaseId = response.data?.Id;
|
||||
const exchange =
|
||||
@@ -8033,6 +8048,8 @@ export class ClaimRequestManagementService {
|
||||
`${logPrefix} Starting submission for claimCaseId: ${claimCaseId}`,
|
||||
);
|
||||
|
||||
const manualSubmission =
|
||||
bodyOverride != null && Object.keys(bodyOverride).length > 0;
|
||||
const existing = await this.claimCaseDbService.findById(claimCaseId);
|
||||
if (existing?.claimId != null) {
|
||||
this.logger.log(
|
||||
@@ -8052,6 +8069,7 @@ export class ClaimRequestManagementService {
|
||||
? await this.tejaratNotifierAllowedIds(clientKey)
|
||||
: undefined;
|
||||
if (
|
||||
!manualSubmission &&
|
||||
!hasReviewedTejaratNotifier(
|
||||
existing.fanavaranFieldReview?.values,
|
||||
clientKey,
|
||||
@@ -8073,23 +8091,45 @@ export class ClaimRequestManagementService {
|
||||
};
|
||||
|
||||
const built = await this.previewFanavaranSubmitV2(claimCaseId, clientKey, {
|
||||
requirePolicyId: true,
|
||||
registerMissingHullDriver: true,
|
||||
requirePolicyId: !manualSubmission,
|
||||
requireClaimExpertId: !manualSubmission,
|
||||
registerMissingHullDriver: !Object.prototype.hasOwnProperty.call(
|
||||
bodyOverride ?? {},
|
||||
'AccidentCulpritId',
|
||||
),
|
||||
auditSession,
|
||||
persistPayload: true,
|
||||
forceRefreshPolicy: true,
|
||||
forceRefreshUsedId: true,
|
||||
...(Object.prototype.hasOwnProperty.call(bodyOverride ?? {}, 'PolicyId')
|
||||
? { policyIdOverride: bodyOverride.PolicyId }
|
||||
: {}),
|
||||
});
|
||||
const product = await this.resolveFanavaranClaimProduct(claimCaseId);
|
||||
const generated =
|
||||
built && typeof built === 'object' && 'payload' in built
|
||||
? built.payload
|
||||
: built;
|
||||
const fanavaranData = applyFanavaranManualPayloadOverrides(
|
||||
built,
|
||||
generated,
|
||||
bodyOverride,
|
||||
FANAVARAN_BASE_MANUAL_OVERRIDE_KEYS,
|
||||
);
|
||||
|
||||
// Guardrail: never send empty/null licence fields even if manual overrides arrive.
|
||||
fanavaranData.CulpritLicenceNo = this.ensureFanavaranNonEmptyLicenceNo(
|
||||
fanavaranData.CulpritLicenceNo,
|
||||
);
|
||||
if (
|
||||
product === 'car-body' &&
|
||||
!Object.prototype.hasOwnProperty.call(bodyOverride ?? {}, 'IsLicenseReplaced')
|
||||
) {
|
||||
fanavaranData.IsLicenseReplaced = resolveFanavaranHullIsLicenseReplaced(
|
||||
fanavaranData.CulpritLicenceIssuDate,
|
||||
fanavaranData.AccidentDate,
|
||||
);
|
||||
}
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(bodyOverride ?? {}, 'CulpritLicenceNo')) {
|
||||
fanavaranData.CulpritLicenceNo = this.ensureFanavaranNonEmptyLicenceNo(
|
||||
fanavaranData.CulpritLicenceNo,
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.log(
|
||||
`${logPrefix} Mapped data prepared:`,
|
||||
@@ -8116,7 +8156,13 @@ export class ClaimRequestManagementService {
|
||||
claimCaseId,
|
||||
);
|
||||
const submitUrl = await this.fanavaranClaimsUrlForClaim(claimCaseId);
|
||||
await this.assertFanavaranHullApiValues(submitUrl, fanavaranData, clientKey, claimCaseId);
|
||||
await this.assertFanavaranHullApiValues(
|
||||
submitUrl,
|
||||
fanavaranData,
|
||||
clientKey,
|
||||
claimCaseId,
|
||||
manualSubmission,
|
||||
);
|
||||
|
||||
const requestHeaders = {
|
||||
...headers,
|
||||
|
||||
@@ -223,4 +223,13 @@ describe("expertise submit completes earlier Fanavaran stages", () => {
|
||||
"expertise",
|
||||
]);
|
||||
});
|
||||
it("applies arbitrary expertise fields and replaces supplied damage sections", async () => {
|
||||
const { service } = setup("car-body");
|
||||
const body = { ClaimExpertId: 999, DmgSections: [{ AccessoryKindId: 42 }], CustomField: null };
|
||||
await service.submitFanavaranExpertiseV2("claim-1", "parsian", body);
|
||||
expect(service.executeFanavaranExpertiseSubmit).toHaveBeenCalledWith(
|
||||
"claim-1", "parsian", expect.objectContaining(body), expect.anything(), true,
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ function setup(accessories: unknown) {
|
||||
"vehicle-hull-dmg-cost-kinds": [
|
||||
{ Id: 8002, Caption: "مجموع لوازم", IsActive: 1 },
|
||||
],
|
||||
"car-components": [{ Id: 9 }, { Id: 13 }, { Id: 112 }],
|
||||
"car-components": [9, 13, 112, 10, 48, 76, 29, 100, 37].map(Id => ({ Id })),
|
||||
})[name] ?? [],
|
||||
);
|
||||
service.fanavaranLookupService = {
|
||||
@@ -19,16 +19,19 @@ function setup(accessories: unknown) {
|
||||
.fn()
|
||||
.mockResolvedValue(accessories),
|
||||
};
|
||||
const build = (policyId = 123) =>
|
||||
const build = (
|
||||
policyId = 123,
|
||||
parts: any[] = [
|
||||
{ partId: 9, partName: "سپر جلو", price: 50000000, salary: 25000000 },
|
||||
{ partId: 13, partName: "چراغ جلو چپ", price: 0, salary: 2000000 },
|
||||
],
|
||||
) =>
|
||||
service.buildCarBodyFanavaranExpertisePayload({
|
||||
clientKey: "parsian",
|
||||
claimCase: { fanavaranSync: { baseClaim: { policyId } } },
|
||||
blame: { parties: [] },
|
||||
profile: {},
|
||||
parts: [
|
||||
{ partId: 9, partName: "سپر جلو", price: 50000000, salary: 25000000 },
|
||||
{ partId: 13, partName: "چراغ جلو چپ", price: 0, salary: 2000000 },
|
||||
],
|
||||
parts,
|
||||
claimExpertId: 4044,
|
||||
submittedAt: new Date("2026-11-11T09:09:00Z"),
|
||||
priceDropTotal: 0,
|
||||
@@ -82,12 +85,14 @@ describe("hull expertise policy accessory mapping", () => {
|
||||
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
|
||||
).toEqual([3061139, 3061139]);
|
||||
expect(payload.DmgSections.map((row: any) => row.AccessoryKindId)).toEqual([
|
||||
112, 112,
|
||||
9, 13,
|
||||
]);
|
||||
expect(warnings).toEqual([]);
|
||||
expect(infoWarnings).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("mapped to factory bundle VehicleHullAccessoryId=3061139 AccessoryKindId=112"),
|
||||
expect.stringContaining(
|
||||
"mapped to factory bundle VehicleHullAccessoryId=3061139; preserving AccessoryKindId=9",
|
||||
),
|
||||
]),
|
||||
);
|
||||
});
|
||||
@@ -157,7 +162,7 @@ describe("hull expertise policy accessory mapping", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("matches by part caption and keeps AccessoryKindId from that policy row", async () => {
|
||||
it("resolves the policy reference by caption without replacing the evaluated partId", async () => {
|
||||
const { build } = setup([
|
||||
{
|
||||
Id: 900010,
|
||||
@@ -168,9 +173,71 @@ describe("hull expertise policy accessory mapping", () => {
|
||||
const { payload, warnings } = await build();
|
||||
expect(payload.DmgSections[0]).toMatchObject({
|
||||
VehicleHullAccessoryId: 900010,
|
||||
AccessoryKindId: 44,
|
||||
AccessoryKindId: 9,
|
||||
});
|
||||
expect(payload.DmgSections[1].VehicleHullAccessoryId).toBeNull();
|
||||
expect(warnings.some((w) => w.includes("چراغ جلو چپ"))).toBe(true);
|
||||
});
|
||||
it("preserves the six saved expert-reply part IDs under shared factory coverage", async () => {
|
||||
const savedReplyParts = [
|
||||
{
|
||||
partId: 10,
|
||||
carPartDamage: { id: 10, label_fa: "سپر عقب" },
|
||||
typeOfDamage: "تعویض",
|
||||
price: "150000000",
|
||||
salary: "30000000",
|
||||
daghi: { option: "ارزش لوازم بازیافتی", price: "20000000" },
|
||||
},
|
||||
{
|
||||
partId: 48,
|
||||
carPartDamage: { id: 48, label_fa: "درب صندوق عقب" },
|
||||
typeOfDamage: "تعمیر",
|
||||
salary: "80000000",
|
||||
},
|
||||
{
|
||||
partId: 76,
|
||||
carPartDamage: { id: 76, label_fa: "سيني عقب" },
|
||||
typeOfDamage: "تعمیر",
|
||||
salary: "70000000",
|
||||
},
|
||||
{
|
||||
partId: 29,
|
||||
carPartDamage: { id: 29, label_fa: "راهنماي عقب راست" },
|
||||
typeOfDamage: "تعویض",
|
||||
price: "95000000",
|
||||
salary: "5000000",
|
||||
},
|
||||
{
|
||||
partId: 100,
|
||||
carPartDamage: { id: 100, label_fa: "سنسور دنده عقب" },
|
||||
typeOfDamage: "تعویض",
|
||||
price: "25000000",
|
||||
salary: "5000000",
|
||||
},
|
||||
{
|
||||
partId: 37,
|
||||
carPartDamage: { id: 37, label_fa: "گلگير عقب سمت سرنشين" },
|
||||
typeOfDamage: "تعمیر",
|
||||
salary: "40000000",
|
||||
},
|
||||
];
|
||||
const { build } = setup([
|
||||
{ Id: 3092174, AccessoryKindId: 112, AccessoryDesc: "کليه قطعات فابريک" },
|
||||
]);
|
||||
const { payload, warnings } = await build(123, savedReplyParts);
|
||||
expect(warnings).toEqual([]);
|
||||
expect(payload.DmgSections.map((row: any) => row.AccessoryKindId)).toEqual([
|
||||
10, 48, 76, 29, 100, 37,
|
||||
]);
|
||||
expect(
|
||||
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
|
||||
).toEqual(Array(6).fill(3092174));
|
||||
expect(payload.DmgSections.map((row: any) => row.Desc)).toEqual(
|
||||
savedReplyParts.map((part) => part.carPartDamage.label_fa),
|
||||
);
|
||||
expect(
|
||||
payload.DmgSections.map((row: any) => row.DmgSectionCosts[0].Amount),
|
||||
).toEqual([180000000, 80000000, 70000000, 100000000, 30000000, 40000000]);
|
||||
expect(payload.DmgSections[0].WasteValue).toBe(20000000);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,17 +34,17 @@ describe("fanavaran hull base claim", () => {
|
||||
expect(fanavaranHullNestedClaimId({ ClaimNo: 2268 })).toBeNull();
|
||||
});
|
||||
|
||||
it("sets IsLicenseReplaced to 1 when licence issue is more than 10 years before accident", () => {
|
||||
it("leaves IsLicenseReplaced empty when licence issue is more than 10 years before accident", () => {
|
||||
const hull = toFanavaranHullBaseClaimPayload({
|
||||
PolicyId: 1,
|
||||
AccidentDate: "1405/08/20",
|
||||
CulpritLicenceIssuDate: "1394/10/13",
|
||||
});
|
||||
expect(hull.IsLicenseReplaced).toBe(1);
|
||||
expect(hull.IsLicenseReplaced).toBeNull();
|
||||
expect(hull).not.toHaveProperty("IsLicenseReplacement");
|
||||
});
|
||||
|
||||
it("sets IsLicenseReplaced to null when licence issue is within 10 years", () => {
|
||||
it("sets IsLicenseReplaced to null when licence issue is more than three years before accident", () => {
|
||||
const hull = toFanavaranHullBaseClaimPayload({
|
||||
PolicyId: 1,
|
||||
AccidentDate: "1405/08/20",
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -134,13 +134,14 @@ function normalizeAccessoryCaption(value: unknown): string {
|
||||
|
||||
export type ResolvedHullDmgAccessory = {
|
||||
vehicleHullAccessoryId: number;
|
||||
/** Must come from the same policy dmg-accessories row (Fanavaran filter rule). */
|
||||
/** Policy-row metadata; does not replace the saved expert-reply partId. */
|
||||
accessoryKindId: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* GEN.06 accessory pair from `GET …/vehicle-hull-policies/{policyId}/dmg-accessories`.
|
||||
* Only returns a coherent Id + AccessoryKindId from one policy row.
|
||||
* Returns the policy coverage reference and that policy row's metadata.
|
||||
* The caller preserves the evaluated partId as DmgSections[].AccessoryKindId.
|
||||
* Exact/caption match only. Factory-bundle fallback for unmatched parts is applied
|
||||
* by the expertise builder (VehicleHullAccessoryId from «کليه قطعات فابريک»).
|
||||
*/
|
||||
|
||||
@@ -199,7 +199,7 @@ export function collectFanavaranExpertiseReadinessWarnings(
|
||||
if (!thirdPartyLookups) {
|
||||
// VehicleHullAccessoryId may be null: many hull policies only list the
|
||||
// factory bundle (کليه قطعات فابريک), not every car-components part.
|
||||
// Do not invent a factory Id with a mismatched AccessoryKindId.
|
||||
// A shared coverage bundle must not replace the evaluated part kind.
|
||||
if (row.AccessoryKindId == null || row.AccessoryKindId === "") {
|
||||
warnings.push(
|
||||
`DmgSections[${index}].AccessoryKindId is required from car-components (selected part).`,
|
||||
|
||||
@@ -187,4 +187,28 @@ describe("hull live lookup submission checks", () => {
|
||||
ActualPremium: 123456,
|
||||
});
|
||||
});
|
||||
it("validates a manual payload without normalizing values or refreshing the supplied premium", async () => {
|
||||
const service = setup();
|
||||
const ids = {
|
||||
cities: 801, "accident-report-type": 802, "accident-causes": 803,
|
||||
"vehicle-hull-accident-types": 804, "vehicle-hull-accident-culprit-type": 805,
|
||||
"detection-accident-culprits": 806, "driving-licence-types": 807, "vehicle-use-types": 808,
|
||||
};
|
||||
service.fanavaranLookupService.fetchFromFanavaran.mockImplementation(async (_client, url) => [
|
||||
{ Id: ids[url.split("/").at(-1)], IsActive: 1 },
|
||||
]);
|
||||
service.fanavaranLookupService.bodyPolicyById = jest.fn().mockResolvedValue({ TotalPremium: 123456 });
|
||||
const payload = {
|
||||
PolicyId: 1, ActualPremium: 12, AccidentCityId: "801", AccidentReportTypeId: 802,
|
||||
AccidentCauseId: 803, AccidentTypeId: 804, CulpritTypeId: 805,
|
||||
AuthorityCulpritId: 806, CulpritLicenceTypeId: 807, AccidentVehicleUsedId: 808,
|
||||
IsLicenseReplaced: null,
|
||||
};
|
||||
const original = JSON.parse(JSON.stringify(payload));
|
||||
await service.postFanavaranJson("https://example.test/car/vehicle-hull-claims", payload, "parsian", undefined, undefined, true);
|
||||
expect(payload).toEqual(original);
|
||||
expect(service.httpService.post).toHaveBeenCalledWith(expect.any(String), original, expect.any(Object));
|
||||
expect(service.fanavaranLookupService.bodyPolicyById).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
import { ClaimRequestManagementService } from "./claim-request-management.service";
|
||||
import { toFanavaranHullBaseClaimPayload } from "./fanavaran-hull-base-claim";
|
||||
|
||||
function setup(product = "car-body") {
|
||||
const service = Object.create(ClaimRequestManagementService.prototype) as any;
|
||||
service.logger = { log: jest.fn(), warn: jest.fn(), error: jest.fn() };
|
||||
service.claimCaseDbService = { findById: jest.fn().mockResolvedValue({}) };
|
||||
service.fanavaranAuditService = { generateTrackingCode: () => "test" };
|
||||
service.fanavaranAuthService = { assertNotInBackoff: jest.fn() };
|
||||
service.previewFanavaranSubmitV2 = jest.fn().mockResolvedValue({
|
||||
PolicyId: 1,
|
||||
AccidentVehicleUsedId: 1,
|
||||
AccidentCauseId: 6,
|
||||
CulpritLicenceNo: "1234567890",
|
||||
IsLicenseReplaced: 1,
|
||||
});
|
||||
service.resolveFanavaranClaimProduct = jest.fn().mockResolvedValue(product);
|
||||
service.getFanavaranAuthHeaders = jest.fn().mockResolvedValue({});
|
||||
service.fanavaranClaimsUrlForClaim = jest
|
||||
.fn()
|
||||
.mockResolvedValue("https://example.test/car/vehicle-hull-claims");
|
||||
const stop = new Error("Captured before HTTP POST");
|
||||
service.assertFanavaranHullApiValues = jest.fn().mockRejectedValue(stop);
|
||||
return { service, stop };
|
||||
}
|
||||
|
||||
describe("hull licence replacement at submit", () => {
|
||||
it("honours explicit null from the submit body before validating the outgoing hull payload", async () => {
|
||||
const { service, stop } = setup();
|
||||
await expect(
|
||||
service.executeFanavaranV2Submit("claim", "parsian", {
|
||||
IsLicenseReplaced: null,
|
||||
PolicyId: 999,
|
||||
AccidentVehicleUsedId: 999,
|
||||
}),
|
||||
).rejects.toBe(stop);
|
||||
const outgoing = service.assertFanavaranHullApiValues.mock.calls[0][1];
|
||||
expect(outgoing.IsLicenseReplaced).toBeNull();
|
||||
expect(outgoing.PolicyId).toBe(999);
|
||||
expect(outgoing.AccidentVehicleUsedId).toBe(999);
|
||||
});
|
||||
|
||||
it("applies all supplied fields on third-party submissions too", async () => {
|
||||
const { service, stop } = setup("third-party");
|
||||
await expect(
|
||||
service.executeFanavaranV2Submit("claim", "parsian", {
|
||||
IsLicenseReplaced: null,
|
||||
}),
|
||||
).rejects.toBe(stop);
|
||||
expect(
|
||||
service.assertFanavaranHullApiValues.mock.calls[0][1].IsLicenseReplaced,
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("builds null for the old licence and accident dates from the rejected request", () => {
|
||||
expect(
|
||||
toFanavaranHullBaseClaimPayload({
|
||||
CulpritLicenceIssuDate: "1381/03/26",
|
||||
AccidentDate: "1405/08/30",
|
||||
}).IsLicenseReplaced,
|
||||
).toBeNull();
|
||||
});
|
||||
it.each([0, 1, null])(
|
||||
"preserves the explicit hull answer %s",
|
||||
async (answer) => {
|
||||
const { service, stop } = setup();
|
||||
await expect(
|
||||
service.executeFanavaranV2Submit("claim", "parsian", {
|
||||
IsLicenseReplaced: answer,
|
||||
}),
|
||||
).rejects.toBe(stop);
|
||||
expect(
|
||||
service.assertFanavaranHullApiValues.mock.calls[0][1].IsLicenseReplaced,
|
||||
).toBe(answer);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
["1381/03/26", null],
|
||||
["1404/08/30", 0],
|
||||
])(
|
||||
"derives an omitted hull answer from the final overridden licence date %s",
|
||||
async (date, answer) => {
|
||||
const { service, stop } = setup();
|
||||
await expect(
|
||||
service.executeFanavaranV2Submit("claim", "parsian", {
|
||||
CulpritLicenceIssuDate: date,
|
||||
AccidentDate: "1405/08/30",
|
||||
}),
|
||||
).rejects.toBe(stop);
|
||||
expect(
|
||||
service.assertFanavaranHullApiValues.mock.calls[0][1].IsLicenseReplaced,
|
||||
).toBe(answer);
|
||||
},
|
||||
);
|
||||
it("preserves null licence numbers, arbitrary fields and nested arrays in the final payload", async () => {
|
||||
const { service, stop } = setup();
|
||||
const body = {
|
||||
CulpritLicenceNo: null,
|
||||
ActualPremium: 12,
|
||||
ClaimExpertId: 888,
|
||||
CustomField: { nested: [1, null, { value: false }] },
|
||||
DmgSections: [{ AccessoryKindId: 42 }],
|
||||
};
|
||||
await expect(
|
||||
service.executeFanavaranV2Submit("claim", "parsian", body),
|
||||
).rejects.toBe(stop);
|
||||
expect(service.assertFanavaranHullApiValues.mock.calls[0][1]).toMatchObject(
|
||||
body,
|
||||
);
|
||||
expect(service.assertFanavaranHullApiValues.mock.calls[0][4]).toBe(true);
|
||||
});
|
||||
|
||||
it("merges against the generated payload rather than forwarding a preview warning envelope", async () => {
|
||||
const { service, stop } = setup();
|
||||
service.previewFanavaranSubmitV2.mockResolvedValue({
|
||||
payload: { PolicyId: null, ActualPremium: null },
|
||||
previewWarnings: [{ field: "PolicyId" }],
|
||||
});
|
||||
await expect(
|
||||
service.executeFanavaranV2Submit("claim", "parsian", {
|
||||
PolicyId: 999,
|
||||
ActualPremium: 12,
|
||||
}),
|
||||
).rejects.toBe(stop);
|
||||
const outgoing = service.assertFanavaranHullApiValues.mock.calls[0][1];
|
||||
expect(outgoing.PolicyId).toBe(999);
|
||||
expect(outgoing).not.toHaveProperty("payload");
|
||||
expect(outgoing).not.toHaveProperty("previewWarnings");
|
||||
expect(service.previewFanavaranSubmitV2).toHaveBeenCalledWith(
|
||||
"claim",
|
||||
"parsian",
|
||||
expect.objectContaining({
|
||||
policyIdOverride: 999,
|
||||
requirePolicyId: false,
|
||||
requireClaimExpertId: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
it("sends every supplied value to the HTTP client without replacing null licence numbers", async () => {
|
||||
const { service, stop } = setup();
|
||||
service.assertFanavaranHullApiValues.mockResolvedValue(undefined);
|
||||
service.fanavaranAuthService.registerFailure = jest.fn();
|
||||
service.fanavaranAuditService.recordStep = jest.fn();
|
||||
service.fanavaranAuditService.captureAxiosExchange = jest
|
||||
.fn()
|
||||
.mockReturnValue({});
|
||||
service.fanavaranAuditService.extractErrorMessage = jest
|
||||
.fn()
|
||||
.mockReturnValue(stop.message);
|
||||
service.fanavaranAuditService.sanitizeErrorDetails = jest
|
||||
.fn()
|
||||
.mockReturnValue({});
|
||||
service.httpService = {
|
||||
post: jest.fn().mockImplementation(() => {
|
||||
throw stop;
|
||||
}),
|
||||
};
|
||||
const body = {
|
||||
PolicyId: 999,
|
||||
ActualPremium: 12,
|
||||
AccidentVehicleUsedId: 42,
|
||||
CulpritLicenceNo: null,
|
||||
IsLicenseReplaced: null,
|
||||
ArbitraryField: false,
|
||||
};
|
||||
await expect(
|
||||
service.executeFanavaranV2Submit("claim", "parsian", body),
|
||||
).rejects.toBe(stop);
|
||||
expect(service.httpService.post).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
expect.objectContaining(body),
|
||||
expect.any(Object),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -111,7 +111,7 @@ export class FanavaranController {
|
||||
@ApiOperation({
|
||||
summary: "Submit Fanavaran base claim create request",
|
||||
description:
|
||||
"Swagger JSON body is optional. Always rebuilds GEN.03 from live inquiries, then POSTs that rebuilt payload. Pasting a previous preview JSON does not skip inquiry. Only user-entry keys are applied from the body (EstimateAmount, licence, dates, address, police report). PolicyId and AccidentVehicleUsedId in pasted JSON are ignored.",
|
||||
"Optional JSON overrides the generated GEN.03 defaults. Every supplied field takes precedence, including lookup IDs, nested objects, arrays and explicit null. Omitted fields retain generated defaults. Validation checks the final payload without rewriting supplied values.",
|
||||
})
|
||||
@ApiParam({
|
||||
name: "client",
|
||||
@@ -125,7 +125,7 @@ export class FanavaranController {
|
||||
@ApiBody({
|
||||
required: false,
|
||||
description:
|
||||
"Optional. Paste previous preview JSON if you want to tweak user-entry fields. Lookup ids in that JSON are ignored.",
|
||||
"Optional JSON payload overrides. All supplied fields are applied as-is; arrays and nested objects replace their generated counterparts. Explicit null is preserved.",
|
||||
schema: { type: "object", additionalProperties: true, example: {} },
|
||||
})
|
||||
async submit(
|
||||
@@ -171,7 +171,7 @@ export class FanavaranController {
|
||||
@ApiOperation({
|
||||
summary: "Submit Fanavaran damage-case request",
|
||||
description:
|
||||
"Swagger JSON body is optional. Always rebuilds GEN.12 from live VIN/vehicle/driver inquiries, then POSTs that rebuilt payload. Pasting a previous preview JSON does not skip inquiry. Only Desc, EstimateAmount, LicenceNo, LicenceIssuDate, DriverIsOwner are taken from the body. PlaqueKindId, PlaqueSampleId, VehicleKindId, DriverId, InsuranceCorpId in pasted JSON are ignored.",
|
||||
"Optional JSON overrides the generated GEN.12 defaults. Every supplied field takes precedence, including DriverId, plaque/vehicle IDs, nested objects, arrays and null. Omitted fields retain generated defaults.",
|
||||
})
|
||||
@ApiParam({
|
||||
name: "client",
|
||||
@@ -185,7 +185,7 @@ export class FanavaranController {
|
||||
@ApiBody({
|
||||
required: false,
|
||||
description:
|
||||
"Optional. Paste previous preview JSON if you want to tweak Desc / licence / estimate. Lookup-filter ids in that JSON are ignored.",
|
||||
"Optional JSON overrides. Every supplied field is applied as-is, including IDs and explicit null.",
|
||||
schema: { type: "object", additionalProperties: true, example: {} },
|
||||
})
|
||||
async submitDamageCase(
|
||||
@@ -283,7 +283,7 @@ export class FanavaranController {
|
||||
@ApiOperation({
|
||||
summary: "Submit Fanavaran expertise request",
|
||||
description:
|
||||
"Completes missing prerequisite stages in order before expertise: base claim, third-party damage case when applicable, then all pending attachments. Skipped images are retried; any image without a saved Fanavaran file ID blocks expertise with stage and pendingFiles details. Existing IDs/receipts are reused; existing expertise is not duplicated. Optional JSON overrides only allowed money/date fields; the GEN.08 third-party or GEN.06 hull payload is rebuilt from the expert reply and live lookups.",
|
||||
"Completes missing prerequisite stages in order before expertise: base claim, third-party damage case when applicable, then all pending attachments. Skipped images are retried; any image without a saved Fanavaran file ID blocks expertise with stage and pendingFiles details. Existing IDs/receipts are reused; existing expertise is not duplicated. Optional JSON overrides every supplied GEN.08 third-party or GEN.06 hull field, including DmgCaseId, ClaimExpertId, DmgSections and explicit null. Omitted fields retain generated defaults.",
|
||||
})
|
||||
@ApiParam({
|
||||
name: "client",
|
||||
@@ -297,7 +297,7 @@ export class FanavaranController {
|
||||
@ApiBody({
|
||||
required: false,
|
||||
description:
|
||||
"Optional. Paste previous preview JSON if you want to tweak money/date fields. DmgCaseId / ClaimExpertId / DmgSections in that JSON are ignored.",
|
||||
"Optional JSON overrides every supplied field. IDs, arrays, nested objects and explicit null take precedence over generated defaults.",
|
||||
schema: { type: "object", additionalProperties: true, example: {} },
|
||||
})
|
||||
async submitExpertise(
|
||||
|
||||
@@ -476,7 +476,7 @@ describe("fanavaran last car policy", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps live PlaqueKindId 8 when Swagger body still has stale 15", () => {
|
||||
it("applies all submitted fields while keeping omitted generated defaults", () => {
|
||||
expect(
|
||||
applyFanavaranManualPayloadOverrides(
|
||||
{
|
||||
@@ -491,11 +491,10 @@ describe("fanavaran last car policy", () => {
|
||||
PlaqueSampleId: 24,
|
||||
Desc: "سپر جلو (edited)",
|
||||
},
|
||||
["Desc", "EstimateAmount", "LicenceNo"],
|
||||
),
|
||||
).toEqual({
|
||||
PlaqueKindId: 8,
|
||||
PlaqueSampleId: 10,
|
||||
PlaqueKindId: 15,
|
||||
PlaqueSampleId: 24,
|
||||
VehicleKindId: 6704,
|
||||
AccidentVehicleUsedId: 1,
|
||||
Desc: "سپر جلو (edited)",
|
||||
|
||||
@@ -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