fix(flow-ui): enable explicit person role registration

Expose person registration for hull claims, require selection of the supported role 166 and check that role even when a driver ID is cached. Keep claim notifier validation out of person registration and populate the verified hull driver reference after success.
This commit is contained in:
2026-11-21 13:33:41 +03:30
parent 99e6fa0850
commit 7bff702514
4 changed files with 189 additions and 17 deletions
+24 -12
View File
@@ -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