Compare commits

...
5 Commits
Author SHA1 Message Date
s.hajizadeh 8f15040080 chore(parsian-seeds): add the missing field expert code 2026-11-21 10:34:20 +03:30
s.hajizadeh 5818f7f881 feat(flow-ui): load branch staff from parsian seeds
Load seeded staff and product-specific codes, preserve intentional missing-code markers, and disable options without codes.
2026-11-21 10:34:07 +03:30
s.hajizadeh 5242a22c6c fix(flow-ui): require a hull report description
Collect and validate the description before hull submission.
2026-11-21 10:33:50 +03:30
s.hajizadeh 9197bccceb fix(flow-ui): reject failed and empty vehicle inquiries
Validate provider responses and populate supported policy aliases.
2026-11-21 10:33:37 +03:30
s.hajizadeh cda424a536 fix(claims): defer flow 1 fanavaran submission at creation
Skip creation-time submission for Flow 1 while preserving branch validation, later staged submission, and other flows.
2026-11-21 10:33:11 +03:30
9 changed files with 307 additions and 91 deletions
+2
View File
@@ -20,6 +20,8 @@ Invalid IDs, inactive branches and branches from another insurer are rejected wi
`createClaimFromBlameV2` revalidates the active branch and copies `blame.branchId` to `claim.branchId`. Missing/invalid selection prevents creation and automatic Fanavaran submission. Changing browser state or calling the creation endpoint directly cannot omit branch validation. This adds no Fanavaran lookup ID or payload field. `createClaimFromBlameV2` revalidates the active branch and copies `blame.branchId` to `claim.branchId`. Missing/invalid selection prevents creation and automatic Fanavaran submission. Changing browser state or calling the creation endpoint directly cannot omit branch validation. This adds no Fanavaran lookup ID or payload field.
Flow 1 skips automatic Fanavaran submission during local claim creation. Later staged submission hooks remain enabled and can create the base Fanavaran claim when needed. Flow 6 and expert/registrar/FileMaker-created flows retain their existing submission timing.
The existing expert claim list filter and detail/assignment/action authorization compare the claim branch with the expert's stored branch, in addition to insurer/tenant isolation. Thus a new routed claim appears in that branch's queue and is rejected for damage experts from another branch, including direct access by case ID. Missing expert branch assignments are already denied. Insurer administrators should assign claim experts to the appropriate branches before rollout. The existing expert claim list filter and detail/assignment/action authorization compare the claim branch with the expert's stored branch, in addition to insurer/tenant isolation. Thus a new routed claim appears in that branch's queue and is rejected for damage experts from another branch, including direct access by case ID. Missing expert branch assignments are already denied. Insurer administrators should assign claim experts to the appropriate branches before rollout.
Existing claims are not migrated or reassigned. Their current access/ownership rules remain in effect. Already-signed blame cases without a claim select their branch on the final screen before entering claim creation. Direct entry into `/claim` also checks selection and returns to that screen if necessary. Deactivation between signing and creation requires choosing another active branch. Existing claims are not migrated or reassigned. Their current access/ownership rules remain in effect. Already-signed blame cases without a claim select their branch on the final screen before entering claim creation. Direct entry into `/claim` also checks selection and returns to that screen if necessary. Deactivation between signing and creation requires choosing another active branch.
+25 -22
View File
@@ -881,6 +881,7 @@
<label class="car-body-only"><b>RepairDuration (روز)</b><input id="REPAIR_DURATION" type="number" min="1" max="255" value="3" required /></label> <label class="car-body-only"><b>RepairDuration (روز)</b><input id="REPAIR_DURATION" type="number" min="1" max="255" value="3" required /></label>
<label><b>COMPONENT_REPLACEMENT_COST</b><input id="COMPONENT_REPLACEMENT_COST" value="500000" /></label> <label><b>COMPONENT_REPLACEMENT_COST</b><input id="COMPONENT_REPLACEMENT_COST" value="500000" /></label>
<label><b>WASTE_VALUE</b><input id="WASTE_VALUE" value="0" /></label> <label><b>WASTE_VALUE</b><input id="WASTE_VALUE" value="0" /></label>
<label class="car-body-only s2"><b>شرح گزارش (ضروری برای بدنه)</b><textarea id="POLICE_REPORT_DESC" required></textarea></label>
<label class="car-body-only"><b>کد ملی بیمه‌گذار بدنه</b><input id="CAR_BODY_POLICYHOLDER_NC" value="" /></label> <label class="car-body-only"><b>کد ملی بیمه‌گذار بدنه</b><input id="CAR_BODY_POLICYHOLDER_NC" value="" /></label>
<label class="car-body-only"><b>AccidentCauseId</b><select id="ACCIDENT_CAUSE_ID"></select></label> <label class="car-body-only"><b>AccidentCauseId</b><select id="ACCIDENT_CAUSE_ID"></select></label>
<label class="car-body-only"><b>AccidentCityId</b><select id="ACCIDENT_CITY_ID"></select></label> <label class="car-body-only"><b>AccidentCityId</b><select id="ACCIDENT_CITY_ID"></select></label>
@@ -1084,13 +1085,7 @@ node scripts/fanavaran-flow-ui-server.js</pre>
APP_NAME:"", APP_SECRET:"", FANAVARAN_USERNAME:"", FANAVARAN_PASSWORD:"", CORP_ID:"", CONTRACT_ID:"", APP_NAME:"", APP_SECRET:"", FANAVARAN_USERNAME:"", FANAVARAN_PASSWORD:"", CORP_ID:"", CONTRACT_ID:"",
CURL_PROXY:"", CURL_PROXY:"",
}; };
const BRANCHES = { const BRANCHES = /* PARSIAN_BRANCH_SEEDS */ {};
"210110":{name:"شعبه پونک (210110)",makers:[{name:"احمد بستان پیرا",claim:"32"},{name:"مهسا وطن نیا",claim:"34"}],reviewers:[{name:"مهدی روشن دل",tp:"3989"},{name:"مهدی شاملوفرد",tp:"72"}]},
"210050":{name:"شعبه غرب تهران (210050)",makers:[{name:"رسول کرکی",claim:"4662"},{name:"اسماعیل سلطانمحمدی",claim:"4221"},{name:"علیرضا گودرزی پور",claim:"4663"},{name:"مهیار کیایی",claim:"1004"}],reviewers:[{name:"رسول کرکی",tp:"29"},{name:"علیرضا گودرزی پور",tp:"16"},{name:"مهدی شاملوفرد",tp:"72"}]},
"210040":{name:"شعبه شرق تهران (210040)",makers:[{name:"اسداله نجفی پور",claim:"91"},{name:"سهیلا شکوری",claim:"88"},{name:"ناصر عیوضی",claim:"228"}],reviewers:[{name:"مجید امیری",tp:"3985"}]},
"210120":{name:"شعبه والفجر (210120)",makers:[{name:"علیرضا درگاهی",claim:"57"},{name:"داود صدیق",claim:"222"},{name:"مهدی معمارباشی",claim:"216"}],reviewers:[{name:"حسین جعفری",tp:"3542"},{name:"مجید کاظمی",tp:"3992"}]},
"110011":{name:"ستاد مرکزی (110011)",makers:[{name:"اکبر بیگ محمدی",claim:"278"}],reviewers:[{name:"فرهاد ملکی",tp:"60"}]}
};
const ID_KEYS = ["POLICY_ID","CLAIM_ID","CLAIM_NO","DRIVER_ID","DMG_CASE_ID","EXPERTISE_ID","DMG_NOTIFICATION_ID","INSURANCE_CORP_ID_NUM","ACCIDENT_CULPRIT_ID"]; const ID_KEYS = ["POLICY_ID","CLAIM_ID","CLAIM_NO","DRIVER_ID","DMG_CASE_ID","EXPERTISE_ID","DMG_NOTIFICATION_ID","INSURANCE_CORP_ID_NUM","ACCIDENT_CULPRIT_ID"];
/** Cleared when starting a new Fanavaran submit; person/lookup ids like ACCIDENT_CULPRIT_ID stay. */ /** Cleared when starting a new Fanavaran submit; person/lookup ids like ACCIDENT_CULPRIT_ID stay. */
@@ -1351,20 +1346,20 @@ node scripts/fanavaran-flow-ui-server.js</pre>
return; return;
} }
const b = BRANCHES[$("LOCATION").value]; const b = BRANCHES[$("LOCATION").value];
(b && b.makers || []).forEach((m, i) => { const hull = q("FANAVARAN_PRODUCT") === "CAR_BODY";
const o = document.createElement("option"); [[claim, b?.makers || [], hull ? "body" : "claim", preferredClaim],
o.value = m.claim; [exp, b?.reviewers || [], hull ? "body" : "tp", preferredExp]]
o.textContent = m.claim + " — " + m.name; .forEach(([select, experts, codeField, preferred]) => {
if ((preferredClaim && preferredClaim === m.claim) || (!preferredClaim && i === 0)) o.selected = true; experts.forEach((expert) => {
claim.appendChild(o); const code = expert[codeField] || "";
}); const option = document.createElement("option");
(b && b.reviewers || []).filter((r) => r.tp).forEach((r, i) => { option.value = code;
const o = document.createElement("option"); option.textContent = (code || "❌ کد موجود نیست") + " — " + expert.name;
o.value = r.tp; option.disabled = !code;
o.textContent = r.tp + " — " + r.name; if (code && String(preferred || "") === code) option.selected = true;
if ((preferredExp && preferredExp === r.tp) || (!preferredExp && i === 0)) o.selected = true; select.appendChild(option);
exp.appendChild(o); });
}); });
} }
function fillBranches() { function fillBranches() {
@@ -1731,6 +1726,7 @@ node scripts/fanavaran-flow-ui-server.js</pre>
REPAIR_DURATION:q("REPAIR_DURATION"), REPAIR_DURATION:q("REPAIR_DURATION"),
COMPONENT_REPLACEMENT_COST:q("COMPONENT_REPLACEMENT_COST"), COMPONENT_REPLACEMENT_COST:q("COMPONENT_REPLACEMENT_COST"),
WASTE_VALUE:q("WASTE_VALUE"), WASTE_VALUE:q("WASTE_VALUE"),
POLICE_REPORT_DESC:q("POLICE_REPORT_DESC").trim(),
CAR_BODY_POLICYHOLDER_NC:q("CAR_BODY_POLICYHOLDER_NC"), CAR_BODY_POLICYHOLDER_NC:q("CAR_BODY_POLICYHOLDER_NC"),
ACCIDENT_CAUSE_ID:lookupValue("ACCIDENT_CAUSE_ID"), ACCIDENT_CAUSE_ID:lookupValue("ACCIDENT_CAUSE_ID"),
ACCIDENT_CITY_ID:lookupValue("ACCIDENT_CITY_ID"), ACCIDENT_CITY_ID:lookupValue("ACCIDENT_CITY_ID"),
@@ -2075,7 +2071,7 @@ node scripts/fanavaran-flow-ui-server.js</pre>
set("REPAIR_DURATION","REPAIR_DURATION"); set("REPAIR_DURATION","REPAIR_DURATION");
set("COMPONENT_REPLACEMENT_COST","COMPONENT_REPLACEMENT_COST"); set("COMPONENT_REPLACEMENT_COST","COMPONENT_REPLACEMENT_COST");
set("WASTE_VALUE","WASTE_VALUE"); set("WASTE_VALUE","WASTE_VALUE");
["CAR_BODY_POLICYHOLDER_NC","ACCIDENT_CAUSE_ID","ACCIDENT_CITY_ID","ACCIDENT_REPORT_TYPE_ID","HULL_ACCIDENT_TYPE_ID","HULL_CULPRIT_TYPE_ID","HULL_AUTHORITY_CULPRIT_ID","CULPRIT_LICENCE_TYPE_ID","ACCIDENT_VEHICLE_USED_ID","POLICE_OFFICER_ID","HULL_IS_ACCIDENT_OUT_OF_BORDER","HULL_CUSTOMER_FAULT_PERCENT","HULL_COST_SEPARATION","HULL_IS_OWNER_CHANGED","HULL_IS_SURPLUS_ARTICLE_EIGHTH_LAW","HULL_GLASS_BREAK_REASON_ID","VEHICLE_CURRENT_VALUE","HULL_DMG_KIND_ID","HULL_DMG_COST_KIND_ID","VEHICLE_HULL_ACCESSORY_ID","COLOR_ID","PLAQUE_DESIGN_ID","PLAQUE_CITY_ID","ACCIDENT_PERCENT"].forEach((id) => set(id,id)); ["POLICE_REPORT_DESC","CAR_BODY_POLICYHOLDER_NC","ACCIDENT_CAUSE_ID","ACCIDENT_CITY_ID","ACCIDENT_REPORT_TYPE_ID","HULL_ACCIDENT_TYPE_ID","HULL_CULPRIT_TYPE_ID","HULL_AUTHORITY_CULPRIT_ID","CULPRIT_LICENCE_TYPE_ID","ACCIDENT_VEHICLE_USED_ID","POLICE_OFFICER_ID","HULL_IS_ACCIDENT_OUT_OF_BORDER","HULL_CUSTOMER_FAULT_PERCENT","HULL_COST_SEPARATION","HULL_IS_OWNER_CHANGED","HULL_IS_SURPLUS_ARTICLE_EIGHTH_LAW","HULL_GLASS_BREAK_REASON_ID","VEHICLE_CURRENT_VALUE","HULL_DMG_KIND_ID","HULL_DMG_COST_KIND_ID","VEHICLE_HULL_ACCESSORY_ID","COLOR_ID","PLAQUE_DESIGN_ID","PLAQUE_CITY_ID","ACCIDENT_PERCENT"].forEach((id) => set(id,id));
syncProduct(); syncProduct();
ID_KEYS.forEach((k) => { stateIds[k] = env[k] || ""; }); ID_KEYS.forEach((k) => { stateIds[k] = env[k] || ""; });
if (env.CULPRIT_TYPE_ID === "337") $("guiltyRoleMode").value = "1"; if (env.CULPRIT_TYPE_ID === "337") $("guiltyRoleMode").value = "1";
@@ -2339,6 +2335,12 @@ node scripts/fanavaran-flow-ui-server.js</pre>
return; return;
} }
if (q("FANAVARAN_PRODUCT") === "CAR_BODY" && (stage === "base" || stage === "all")) { if (q("FANAVARAN_PRODUCT") === "CAR_BODY" && (stage === "base" || stage === "all")) {
if (!q("POLICE_REPORT_DESC").trim()) {
setStatus("شرح گزارش برای ثبت پرونده بدنه ضروری است.", "err");
showFormTab("accident");
$("POLICE_REPORT_DESC").focus();
return;
}
const requiredLookups = [ const requiredLookups = [
["accident-causes", "ACCIDENT_CAUSE_ID"], ["accident-causes", "ACCIDENT_CAUSE_ID"],
["cities", "ACCIDENT_CITY_ID"], ["cities", "ACCIDENT_CITY_ID"],
@@ -2442,6 +2444,7 @@ node scripts/fanavaran-flow-ui-server.js</pre>
$("LOCATION").addEventListener("change", () => refreshExperts()); $("LOCATION").addEventListener("change", () => refreshExperts());
$("FANAVARAN_PRODUCT").addEventListener("change", () => { $("FANAVARAN_PRODUCT").addEventListener("change", () => {
syncProduct(); syncProduct();
refreshExperts();
$("envOut").value = envToText(collectEnv()); $("envOut").value = envToText(collectEnv());
}); });
["CLAIM_EXPERT_ID", "EXPERTISE_CLAIM_EXPERT_ID"].forEach((id) => { ["CLAIM_EXPERT_ID", "EXPERTISE_CLAIM_EXPERT_ID"].forEach((id) => {
@@ -137,7 +137,8 @@
"branchName": "شعبه والفجر", "branchName": "شعبه والفجر",
"city": "کاشان", "city": "کاشان",
"state": "اصفهان", "state": "اصفهان",
"title": "كارشناس ارزياب خسارت بدنه" "title": "كارشناس ارزياب خسارت بدنه",
"expertCode": "3705"
}, },
{ {
"nationalCode": "3781847039", "nationalCode": "3781847039",
@@ -150,4 +151,4 @@
"title": "كارشناس ارزياب خسارت ثالث مالي" "title": "كارشناس ارزياب خسارت ثالث مالي"
} }
] ]
} }
+29 -29
View File
@@ -23,7 +23,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"ThirdPartyClaimExpertId": "91", "ThirdPartyClaimExpertId": "91",
@@ -37,7 +37,7 @@
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"ThirdPartyClaimExpertId": "4221", "ThirdPartyClaimExpertId": "4221",
@@ -47,7 +47,7 @@
"nationalCode": "0492295557", "nationalCode": "0492295557",
"mobile": "09125409101", "mobile": "09125409101",
"firstName": "اکبر", "firstName": "اکبر",
"lastName": "بيگ محمدي", "lastName": "بيگ محمدي ❌",
"locations": [ "locations": [
{ {
"id": "111130", "id": "111130",
@@ -64,7 +64,7 @@
"nationalCode": "3220096573", "nationalCode": "3220096573",
"mobile": "09104933206", "mobile": "09104933206",
"firstName": "پدرام", "firstName": "پدرام",
"lastName": "حاتمي", "lastName": "حاتمي ❌",
"locations": [ "locations": [
{ {
"id": "210120", "id": "210120",
@@ -81,7 +81,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"ThirdPartyClaimExpertId": "739", "ThirdPartyClaimExpertId": "739",
@@ -95,7 +95,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"CarBodyClaimExpertId": "3215", "CarBodyClaimExpertId": "3215",
@@ -119,11 +119,11 @@
"nationalCode": "0084130938", "nationalCode": "0084130938",
"mobile": "09392558640", "mobile": "09392558640",
"firstName": "رسول", "firstName": "رسول",
"lastName": "کرکي", "lastName": "کرکي ❌",
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"ThirdPartyClaimExpertId": "4662" "ThirdPartyClaimExpertId": "4662"
@@ -136,7 +136,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"ThirdPartyClaimExpertId": "4245", "ThirdPartyClaimExpertId": "4245",
@@ -150,7 +150,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"CarBodyClaimExpertId": "89", "CarBodyClaimExpertId": "89",
@@ -164,7 +164,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"CarBodyClaimExpertId": "4455", "CarBodyClaimExpertId": "4455",
@@ -178,7 +178,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"ThirdPartyClaimExpertId": "742", "ThirdPartyClaimExpertId": "742",
@@ -220,7 +220,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"CarBodyClaimExpertId": "4652", "CarBodyClaimExpertId": "4652",
@@ -244,11 +244,11 @@
"nationalCode": "0066868521", "nationalCode": "0066868521",
"mobile": "09129344240", "mobile": "09129344240",
"firstName": "عليرضا", "firstName": "عليرضا",
"lastName": "گودرزي پور", "lastName": "گودرزي پور ❌",
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"ThirdPartyClaimExpertId": "4663" "ThirdPartyClaimExpertId": "4663"
@@ -261,7 +261,7 @@
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"CarBodyClaimExpertId": "4220", "CarBodyClaimExpertId": "4220",
@@ -275,7 +275,7 @@
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"CarBodyClaimExpertId": "4452", "CarBodyClaimExpertId": "4452",
@@ -299,11 +299,11 @@
"nationalCode": "0056888082", "nationalCode": "0056888082",
"mobile": "09122406750", "mobile": "09122406750",
"firstName": "قاسم", "firstName": "قاسم",
"lastName": "نصراللهي", "lastName": "نصراللهي ❌",
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"ThirdPartyClaimExpertId": "4664" "ThirdPartyClaimExpertId": "4664"
@@ -330,7 +330,7 @@
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"CarBodyClaimExpertId": "4092", "CarBodyClaimExpertId": "4092",
@@ -344,7 +344,7 @@
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"ThirdPartyClaimExpertId": "1010", "ThirdPartyClaimExpertId": "1010",
@@ -354,11 +354,11 @@
"nationalCode": "0493217789", "nationalCode": "0493217789",
"mobile": "09126966943", "mobile": "09126966943",
"firstName": "مصطفي", "firstName": "مصطفي",
"lastName": "محمدزاده قورقچي", "lastName": "محمدزاده قورقچي ❌",
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"ThirdPartyClaimExpertId": "4665" "ThirdPartyClaimExpertId": "4665"
@@ -371,7 +371,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"CarBodyClaimExpertId": "745", "CarBodyClaimExpertId": "745",
@@ -381,11 +381,11 @@
"nationalCode": "0078209129", "nationalCode": "0078209129",
"mobile": "09126038117", "mobile": "09126038117",
"firstName": "مهدي", "firstName": "مهدي",
"lastName": "شاملوفرد", "lastName": "شاملوفرد ❌",
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"ThirdPartyClaimExpertId": "4666" "ThirdPartyClaimExpertId": "4666"
@@ -426,7 +426,7 @@
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"ThirdPartyClaimExpertId": "1004", "ThirdPartyClaimExpertId": "1004",
@@ -440,7 +440,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"ThirdPartyClaimExpertId": "4646", "ThirdPartyClaimExpertId": "4646",
@@ -454,7 +454,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"ThirdPartyClaimExpertId": "228", "ThirdPartyClaimExpertId": "228",
@@ -23,7 +23,7 @@
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"ThirdPartyExpertiseClaim": "29", "ThirdPartyExpertiseClaim": "29",
@@ -50,7 +50,7 @@
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"CarBodyExpertiseClaim": "15", "CarBodyExpertiseClaim": "15",
@@ -74,11 +74,11 @@
"nationalCode": "0056888082", "nationalCode": "0056888082",
"mobile": "09122406750", "mobile": "09122406750",
"firstName": "قاسم", "firstName": "قاسم",
"lastName": "نصراللهي", "lastName": "نصراللهي ❌",
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"ThirdPartyExpertiseClaim": "4645" "ThirdPartyExpertiseClaim": "4645"
@@ -91,7 +91,7 @@
"locations": [ "locations": [
{ {
"id": "210040", "id": "210040",
"name": "شعبه شرق تهران(210040)" "name": "شعبه شرق تهران"
} }
], ],
"ThirdPartyExpertiseClaim": "3985", "ThirdPartyExpertiseClaim": "3985",
@@ -119,7 +119,7 @@
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
} }
], ],
"ThirdPartyExpertiseClaim": "3545", "ThirdPartyExpertiseClaim": "3545",
@@ -147,7 +147,7 @@
"locations": [ "locations": [
{ {
"id": "210050", "id": "210050",
"name": "شعبه غرب تهران(210050)" "name": "شعبه غرب تهران"
}, },
{ {
"id": "210110", "id": "210110",
@@ -156,6 +156,43 @@
], ],
"CarBodyExpertiseClaim": "73", "CarBodyExpertiseClaim": "73",
"ThirdPartyExpertiseClaim": "72" "ThirdPartyExpertiseClaim": "72"
},
{
"nationalCode": "3781847039",
"firstName": "اکبر",
"lastName": "ديني ❌",
"locations": [
{
"id": "210040",
"name": "شعبه شرق تهران"
}
]
},
{
"nationalCode": "0759153981",
"firstName": "رضا",
"lastName": "صالحي زاده ❌",
"locations": [
{
"id": "210040",
"name": "شعبه شرق تهران"
}
]
},
{
"nationalCode": "0013480261",
"firstName": "عليرضا",
"lastName": "خازني ❌",
"locations": [
{
"id": "210040",
"name": "شعبه شرق تهران"
},
{
"id": "210110",
"name": "شعبه پونک"
}
]
} }
] ]
} }
+72 -27
View File
@@ -51,7 +51,7 @@ function loadRootDotEnv() {
function httpJson(method, url, body, headers) { function httpJson(method, url, body, headers) {
return new Promise((resolve) => { return new Promise((resolve) => {
const args = ["-sS", "--max-time", "45", "-X", method, url, "-H", "Accept: application/json"]; const args = ["-sS", "--max-time", "45", "-w", "\n%{http_code}", "-X", method, url, "-H", "Accept: application/json"];
for (const [k, v] of Object.entries(headers || {})) { for (const [k, v] of Object.entries(headers || {})) {
args.push("-H", `${k}: ${v}`); args.push("-H", `${k}: ${v}`);
} }
@@ -68,13 +68,16 @@ function httpJson(method, url, body, headers) {
stderr += d.toString(); stderr += d.toString();
}); });
child.on("close", (code) => { child.on("close", (code) => {
const statusAt = stdout.lastIndexOf("\n");
const status = Number(stdout.slice(statusAt + 1));
stdout = stdout.slice(0, statusAt);
let json = null; let json = null;
try { try {
json = JSON.parse(stdout || "null"); json = JSON.parse(stdout || "null");
} catch { } catch {
json = null; json = null;
} }
resolve({ code, stdout, stderr, json }); resolve({ code, status, stdout, stderr, json });
}); });
}); });
} }
@@ -105,10 +108,12 @@ function pickVehicleFields(src) {
const built = const built =
data.BuiltYear || data.PrdDte || data.ModelField || data.ModelCii || data.builtYear || ""; data.BuiltYear || data.PrdDte || data.ModelField || data.ModelCii || data.builtYear || "";
const policyNo = const policyNo =
data.PolicyNo || data.PrntCmpDocNo || data.PrntPlcyCmpDocNo || data.printNumber || ""; data.PolicyNo || data.PrntCmpDocNo || data.PrntPlcyCmpDocNo || data.printNumber ||
data.insuranceNumber || data.LastCompanyDocumentNumber || data.lastCompanyInsuranceNumber || data.policyNumber || "";
const policyCi = data.PolicyCINumber || data.PlcyUnqCod || data.ThirdPolicyCode || ""; const policyCi = data.PolicyCINumber || data.PlcyUnqCod || data.ThirdPolicyCode || "";
const begin = data.BeginDate || data.HBgnDte || data.StartDate || ""; const begin = data.BeginDate || data.HBgnDte || data.StartDate || data.SatrtDate ||
const end = data.EndDate || data.HEndDte || ""; data.beginDate || data.persianStartDate || "";
const end = data.EndDate || data.HEndDte || data.endDate || data.persianEndDate || "";
return { return {
MOTOR_NO: String(motor || ""), MOTOR_NO: String(motor || ""),
CHASSIS_NO: String(chassis || ""), CHASSIS_NO: String(chassis || ""),
@@ -121,6 +126,29 @@ function pickVehicleFields(src) {
}; };
} }
function validateVehicleInquiry(res) {
const root = res.json;
const records = [root, root?.data].filter((r) => r && typeof r === "object");
const failed = records.some((r) =>
r.Error || r.error || r.HasError === true || r.hasError === true ||
r.success === false || r.isSuccess === false || r.IsSuccess === false ||
r.IsSucceed === false || r.ReturnValue === false ||
Number(r.statusCode ?? r.status) >= 400,
);
if (res.code !== 0 || res.status >= 400 || !root || failed) {
const detail = records.flatMap((r) => [
r.messageFa, r.Error?.Message, r.error?.message, r.Message, r.message,
]).find((message) => typeof message === "string" && message.trim());
throw new Error(detail || res.stderr || "Vehicle inquiry failed");
}
}
function requireVehicleFields(vehicle) {
if (!Object.values(vehicle).some((value) => String(value).trim())) {
throw new Error("استعلام هیچ اطلاعات خودرو یا بیمه‌نامه‌ای برنگرداند؛ پلاک و کد ملی و پاسخ سرویس را بررسی کنید.");
}
}
function findOfflinePlate(input) { function findOfflinePlate(input) {
if (!fs.existsSync(OFFLINE_SEEDS)) return null; if (!fs.existsSync(OFFLINE_SEEDS)) return null;
const rows = JSON.parse(fs.readFileSync(OFFLINE_SEEDS, "utf8")); const rows = JSON.parse(fs.readFileSync(OFFLINE_SEEDS, "utf8"));
@@ -204,7 +232,15 @@ async function livePlateInquiry(input) {
}, },
{ Authorization: `Bearer ${token}` }, { Authorization: `Bearer ${token}` },
); );
if (res.json && !res.json.Error) { let usable = false;
try {
validateVehicleInquiry(res);
requireVehicleFields(pickVehicleFields(res.json));
usable = true;
} catch {
// Try the existing Tejarat fallback when ESG has no usable result.
}
if (usable) {
return { return {
source: "ESG_carByPlate", source: "ESG_carByPlate",
mode: "plate", mode: "plate",
@@ -229,17 +265,7 @@ async function livePlateInquiry(input) {
}, },
{ Authorization: `Bearer ${token}` }, { Authorization: `Bearer ${token}` },
); );
if (!res.json) { validateVehicleInquiry(res);
throw new Error(res.stderr || "empty inquiry response");
}
if (res.json.Error || res.json.HasError) {
const msg =
res.json.Error?.Message ||
res.json.Message ||
res.json.message ||
"plate inquiry failed";
throw new Error(String(msg));
}
const vehicle = pickVehicleFields(res.json); const vehicle = pickVehicleFields(res.json);
return { return {
source: "TEJARAT_block-inquiry", source: "TEJARAT_block-inquiry",
@@ -282,15 +308,7 @@ async function liveVinInquiry(input) {
}, },
{ Authorization: `Bearer ${token}` }, { Authorization: `Bearer ${token}` },
); );
if (!res.json) throw new Error(res.stderr || "empty VIN inquiry response"); validateVehicleInquiry(res);
if (res.json.Error || res.json.HasError) {
const msg =
res.json.Error?.Message ||
res.json.Message ||
res.json.message ||
"VIN inquiry failed";
throw new Error(String(msg));
}
return { return {
source: "ESG_carByChassis", source: "ESG_carByChassis",
mode: "vin", mode: "vin",
@@ -307,6 +325,7 @@ async function inquireVehicle(input) {
try { try {
const live = const live =
mode === "vin" ? await liveVinInquiry(payload) : await livePlateInquiry(payload); mode === "vin" ? await liveVinInquiry(payload) : await livePlateInquiry(payload);
requireVehicleFields(live.vehicle);
return { ok: true, ...live }; return { ok: true, ...live };
} catch (err) { } catch (err) {
return { ok: false, error: String(err.message || err), mode }; return { ok: false, error: String(err.message || err), mode };
@@ -999,12 +1018,38 @@ function runStage(stage, options = {}) {
}); });
} }
function parsianBranchSeeds() {
const dir = path.join(__dirname, "data", "parsian-tehran");
const read = (file) => JSON.parse(fs.readFileSync(path.join(dir, file), "utf8"));
const branches = Object.fromEntries(read("branches.json").branches.map((b) => [
b.code, { name: `${b.name} (${b.code})`, makers: [], reviewers: [] },
]));
for (const [file, key, role, thirdParty, body] of [
["file-makers.json", "fileMakers", "makers", "ThirdPartyClaimExpertId", "CarBodyClaimExpertId"],
["file-reviewers.json", "fileReviewers", "reviewers", "ThirdPartyExpertiseClaim", "CarBodyExpertiseClaim"],
]) {
for (const expert of read(file)[key]) {
for (const location of expert.locations || []) {
if (!branches[location.id]) continue;
branches[location.id][role].push({
name: `${expert.firstName} ${expert.lastName}`,
[role === "makers" ? "claim" : "tp"]: expert[thirdParty] || "",
body: expert[body] || "",
});
}
}
}
return branches;
}
const server = http.createServer(async (req, res) => { const server = http.createServer(async (req, res) => {
const url = new URL(req.url, `http://${HOST}:${PORT}`); const url = new URL(req.url, `http://${HOST}:${PORT}`);
try { try {
if (req.method === "GET" && (url.pathname === "/" || url.pathname === "/index.html")) { if (req.method === "GET" && (url.pathname === "/" || url.pathname === "/index.html")) {
send(res, 200, fs.readFileSync(UI_HTML, "utf8"), "text/html; charset=utf-8"); const seeds = JSON.stringify(parsianBranchSeeds()).replace(/</g, "\\u003c");
const html = fs.readFileSync(UI_HTML, "utf8").replace("/* PARSIAN_BRANCH_SEEDS */ {}", () => seeds);
send(res, 200, html, "text/html; charset=utf-8");
return; return;
} }
+79
View File
@@ -0,0 +1,79 @@
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");
// Exercise the inquiry entry point without starting the UI or contacting a provider.
function inquiryContext(response) {
const source = fs.readFileSync(path.join(__dirname, "fanavaran-flow-ui-server.js"), "utf8")
.split("const server = http.createServer")[0];
const context = vm.createContext({ require, __dirname, process: { env: {} }, Buffer });
vm.runInContext(source, context);
context.response = response;
vm.runInContext(`
findOfflinePlate = () => null;
getSandhubToken = async () => "test-token";
httpJson = async () => response;
`, context);
return context;
}
for (const [name, json, status] of [
["HTTP error JSON", { statusCode: 401, message: "Unauthorized" }, 401],
["provider failure", { success: false, message: "No policy found" }, 200],
["nested provider failure", { data: { hasError: true, message: "Not found" } }, 200],
["empty result", { data: {} }, 200],
]) {
test(`${name} must not report success with empty vehicle inputs`, async () => {
const context = inquiryContext({ code: 0, status, json });
const result = await vm.runInContext('inquireVehicle({ client: "tejaratno" })', context);
assert.equal(result.ok, false);
assert.ok(result.error);
});
}
test("successful Tejarat inquiry fills vehicle and policy fields", async () => {
const context = inquiryContext({ code: 0, status: 200, json: { data: {
mtrnum: "ENGINE-1", shsNam: "CHASSIS-1", vin: "VIN-1", ModelField: "1400",
insuranceNumber: "POLICY-1", PlcyUnqCod: "12345",
persianStartDate: "1404/01/01", persianEndDate: "1405/01/01",
} } });
const result = await vm.runInContext('inquireVehicle({ client: "tejaratno" })', context);
assert.equal(result.ok, true);
assert.deepEqual(JSON.parse(JSON.stringify(result.vehicle)), {
MOTOR_NO: "ENGINE-1", CHASSIS_NO: "CHASSIS-1", VIN: "VIN-1", BUILT_YEAR: "1400",
POLICY_NO: "POLICY-1", POLICY_CI_NUMBER: "12345",
BEGIN_DATE: "1404/01/01", END_DATE: "1405/01/01",
});
});
test("policy aliases used by existing inquiry mappings populate all three fields", async () => {
const context = inquiryContext({ code: 0, status: 200, json: {
MtrNum: "ENGINE-1", LastCompanyDocumentNumber: "POLICY-2",
SatrtDate: "1404/02/01", endDate: "1405/02/01",
} });
const result = await vm.runInContext('inquireVehicle({ client: "tejaratno" })', context);
assert.equal(result.vehicle.POLICY_NO, "POLICY-2");
assert.equal(result.vehicle.BEGIN_DATE, "1404/02/01");
assert.equal(result.vehicle.END_DATE, "1405/02/01");
});
test("flow UI includes every seed expert in each assigned branch and both Kazemi codes", () => {
const context = inquiryContext({});
const branches = vm.runInContext("parsianBranchSeeds()", context);
for (const [file, key, role] of [
["file-makers.json", "fileMakers", "makers"],
["file-reviewers.json", "fileReviewers", "reviewers"],
]) {
const seeds = JSON.parse(fs.readFileSync(path.join(__dirname, "data/parsian-tehran", file)))[key];
for (const expert of seeds) {
for (const location of expert.locations) {
assert.ok(branches[location.id][role].some(r => r.name === `${expert.firstName} ${expert.lastName}`));
}
}
}
const kazemi = branches["210120"].reviewers.find(r => r.name.includes("کاظمي دولت سرا"));
assert.equal(kazemi.tp, "3992");
assert.equal(kazemi.body, "3991");
});
@@ -90,10 +90,50 @@ describe("claim beneficiary authorization across shared user flows", () => {
expect(saved.owner.userClientKey).toBe(payer); expect(saved.owner.userClientKey).toBe(payer);
expect( expect(
service.autoSubmitToFanavaranV2OnClaimCreated, service.autoSubmitToFanavaranV2OnClaimCreated,
).toHaveBeenCalledTimes(1); ).not.toHaveBeenCalled();
}, },
); );
it.each(["THIRD_PARTY", "CAR_BODY"])(
"defers Flow 1 %s submission at creation while retaining the selected branch",
async (type) => {
const blame = source();
blame.type = type;
blame.branchId = "650000000000000000000099";
if (type === "CAR_BODY") blame.parties = [blame.parties[0]];
const service = serviceFor(blame);
const result = await service.createClaimFromBlameV2(
blameId,
type === "CAR_BODY" ? firstId : secondId,
);
expect(result.fanavaran).toMatchObject({
attempted: false,
submitted: false,
skipped: true,
});
expect(service.autoSubmitToFanavaranV2OnClaimCreated).not.toHaveBeenCalled();
expect(service.userClaimBranchService.validate).toHaveBeenCalledWith(blame, blame.branchId);
expect(String(service.claimCaseDbService.create.mock.calls[0][0].branchId)).toBe(blame.branchId);
},
);
it.each([
{ callCenterInitiated: true },
{ expertInitiated: true, creationMethod: "LINK" },
{ expertInitiated: true, creationMethod: "IN_PERSON" },
{ registrarInitiated: true },
{ isMadeByFileMaker: true },
])("preserves early submission for other flows: %j", async (flags) => {
const service = serviceFor({ ...source(), ...flags });
await service.createClaimFromBlameV2(blameId, secondId);
expect(service.autoSubmitToFanavaranV2OnClaimCreated).toHaveBeenCalledTimes(1);
expect(service.autoSubmitToFanavaranV2OnClaimCreated).toHaveBeenCalledWith(claimId);
});
it("blocks incomplete, unsigned, rejected, and unresolved cases without creating or submitting a claim", async () => { it("blocks incomplete, unsigned, rejected, and unresolved cases without creating or submitting a claim", async () => {
const invalid = [ const invalid = [
{ ...source(), status: "WAITING_FOR_SIGNATURES" }, { ...source(), status: "WAITING_FOR_SIGNATURES" },
@@ -8213,9 +8213,18 @@ export class ClaimRequestManagementService {
`Claim created: ${newClaim._id} from blame: ${blameRequestId}`, `Claim created: ${newClaim._id} from blame: ${blameRequestId}`,
); );
const fanavaran = await this.autoSubmitToFanavaranV2OnClaimCreated( // Flow 1 defers Fanavaran submission to the later staged hooks.
String(newClaim._id), // Flow 6 and expert/registrar-created cases retain early submission.
); const deferFanavaran =
usesUserClaimBranch(blameRequest) && !blameRequest.callCenterInitiated;
const fanavaran: FanavaranAutoSubmitResult = deferFanavaran
? {
attempted: false,
submitted: false,
skipped: true,
skipReason: 'Flow 1 defers Fanavaran submission until a later stage',
}
: await this.autoSubmitToFanavaranV2OnClaimCreated(String(newClaim._id));
const message = this.withFanavaranAutoSubmitMessage( const message = this.withFanavaranAutoSubmitMessage(
'Claim request created successfully', 'Claim request created successfully',
fanavaran, fanavaran,