Files
yara724-api/docs/fanavaran/lookup-coding-audit.md
SepehrYahyaee a15c54d017 feat: route user claims by branch and align licence issue dates
Require the damaged party in user flows to select an active insurer branch and preserve branch access rules. Accept older licence issue dates, correct anniversary boundaries, and update Fanavaran audit documentation and regression coverage.
2026-11-14 12:24:14 +03:30

12 KiB
Raw Permalink Blame History

Fanavaran lookup coding audit

Update (2026-11-11): The latest hull/accessory/location changes supersede several findings below. See the current hardcoded-payload audit for what remains, including exact outbound defaults and standalone tool behavior.

Date: 2026-11-10. Clients: Moallem, Tejaratno, Parsian. Scope: current base, damage-case, attachment, expertise and other-person payload builders shared by app flows V1–V6. This is a code and local-snapshot audit, not a live acceptance test against the three insurers. No runtime mappings were changed by this audit.

Finding

The integration does not yet guarantee correct tenant-specific codes for every outbound field. Tenant-specific URLs and disk folders exist, but several payload builders use unvalidated defaults, and Mongo lookup storage has no tenant key. The recent strict policy-vehicle mapping applies to hull base claims only.

Inquiry-derived values

Fields Current source Remaining limitation
PolicyId Product-specific policy inquiry / previously stored policy reference Stored policy references need client/product provenance when reused across explicit client routes
Base/expertise ClaimExpertId Assigned staff's product-specific Mongo codes Staff profile correctness is required; tenant config expert defaults are excluded
Hull base AccidentVehicleUsedId Hull policy VehicleId + VehicleVersionNo → vehicle GET UsedId Missing inquiry warns / blocks submit; active lookup/group compatibility is not independently revalidated here
Third-party base AccidentVehicleUsedId Guilty VIN inquiry, then policy vehicle, with generic lookup selection; cache/expert review can take precedence Can choose personal/first group row or tenant default rather than preserve the actual inquiry value
Damage-case AccidentVehicleUsedId Approved expert vehicle use, matched damaged vehicle, group lookup, then tenant default Still permits guessed/default codes
Damage-case VehicleKindId Expert selection → matched vehicle GET → caption keyword search from broad local carType Final fallback can select an arbitrary vehicle model from the correct broad category
DriverId, OwnerId Person national code + birthday inquiry, accepted roles 161/166; GEN.44 creation on submit Reused person references need client provenance; these are person record IDs, not generic lookup values
Hull AccidentCulpritId Driver/person inquiry; fallback hull policy CustomerId Driver and policy customer may differ; fallback is not proof of driver identity
Hull ActualPremium Policy GET TotalPremium Already inquiry-derived
Hull VehicleCurrentValue Local/reviewed value, then hull policy VehicleValue Policy insured value is the fallback, not an independent market valuation
Damage-case plaque coding Matched Fanavaran vehicle fields PlaqueKindId/PlaqueSampleId still fall back to national-plate 8/10; plate-letter map is static
Hull ColorId Exact policy vehicle GET Already inquiry-derived when the API returns it
VIN, motor/chassis, plate text, model year, policy number/CI/dates Vehicle/policy inquiries and stored provider-mapped fields These are identity/data values; provider-local numeric codes must not be treated as Fanavaran lookup IDs
InsuranceCorpId Environment caption matched against client's insurance-corp Resolved scalar cache is not tied to caption changes; localhost fallback uses deployment's active tenant, which can differ from an explicit client route

Base-claim codebooks

Field Codebook / correct source Actual current behavior
AccidentCityId cities, based on accident location / explicit selection Tenant default 701 unless reviewed
AccidentReportTypeId accident-report-type, explicit accident report selection Tenant default 155 unless reviewed
AccidentCauseId accident-causes, explicit accident cause Hardcoded 6; builder receives accident reason but does not apply its code
CulpritLicenceTypeId driving-licence-types, correct licence category Tenant default 2
Third-party CulpritTypeId accident-culprit-type Tenant default 337
CompensationReferenceId Confirm the product contract/codebook Tenant default 167; no dedicated remote lookup definition in current catalogue
PoliceOfficerId Confirm the product contract/codebook Hardcoded 1; no dedicated remote lookup definition in current catalogue
Hull AccidentTypeId vehicle-hull-accident-types, actual accident type Reviewed selection, else numeric 2; inactive in Moallem/Tejaratno snapshots
Hull CulpritTypeId vehicle-hull-accident-culprit-type Reviewed selection, else 300; third-party 337 is remapped
Hull AuthorityCulpritId detection-accident-culprits Reviewed selection or caption بیمه‌گذار; then first row / numeric 1 fallback
Tejaratno notifier type/relation notifier-type, notifier-relation Required reviewed choices; shared Mongo source remains a tenant-isolation concern

Reviewed stage choices are checked against active lookup rows when saved. However, defaults and previously stored choices are not uniformly validated against the outbound request's client immediately before submission.

Damage-case, expertise, files and GEN.44 codebooks

Field Codebook / correct source Actual current behavior
Damage DmgCaseTypeId dmg-case-type Tenant default 175
Damage DmgHistoryStatus dmg-history-status Reviewed choice, else tenant default 5214
Damage LicenceTypeId driving-licence-types Tenant CulpritLicenceTypeId, normally 2
Third-party expertise InspectionPlaceId inspection-place Reviewed choice, else 282; lookup is fetched but fallback not selected from it
Third-party expertise DropAmountStatus drop-amount-status Hardcoded 5458 even though lookup is fetched
Third-party DmgSections[].DmgSectionId Client car-components Saved local partId; catalog can fall back to a shared static snapshot; no outbound membership check
Third-party DmgSections[].AccidentLevel Client accident-level Numeric typeOfDamage, else 5456; no outbound codebook validation
Hull DmgSections[].AccessoryKindId Client car-components Saved local partId; same catalogue provenance concern
Hull DmgSections[].DmgKindId vehicle-hull-dmg-kind Exact caption تخریب search; fallback 5485. Persian ی vs Arabic ي mismatch can trigger fallback
Hull section cost DmgCostKindId vehicle-hull-dmg-cost-kinds Caption مجموع لوازم, else 1
Hull VehicleHullAccessoryId Policy GET car/vehicle-hull-policies/{policyId}/dmg-accessories Hardcoded 3043330 for every section; existing lookup API/helper is not wired into builder
Attachment FileTypeId Client file-types, confirmed document category Configured defaults: Moallem 17, Tejaratno 23, Parsian 63; no automatic outbound membership/category validation
GEN.44 CityId User/person city matched to client cities Explicit/inquiry city, caption match, else Parsian-specific 9131
GEN.44 GenderId Inquiry or client gender Inquiry code or caption match
GEN.44 PersonKindId Client person-kind Explicit code or caption حقیقی, else Parsian-specific 46
GEN.44 IsIranian, NationalityId, MaritalStatus Client ans, countries, marital-status plus actual person data Yes/no fallbacks 1/0; marital status unset; nationality not inferred reliably for foreign people

PlaqueDesignId, hull expertise PlaqueCityId/AccidentPercent, licence city/country and glass-break reason are currently generally null, not resolved code mappings. Boolean flags, fault percentages, amounts, dates, counts and text are not all tenant-specific codebook IDs. In particular, the requested hardcoded PoliceReportDesc="شرح گزارش" is text and is unaffected by lookup coding.

Confirmed cross-client differences in local snapshots

Meaning / ID Moallem Tejaratno Parsian
File ID 17 Other documents, active Driving licence, active Police/judicial documents, inactive
File ID 23 Printed form, active Other documents, active Contract/agreement, inactive
Intended general-document file ID 17 23 63
Hull accident ID 2 Collision, inactive Collision, inactive Collision, active
Vehicle vs vehicle hull accident 19, active 18, active No identical dedicated row in snapshot; general collision 2 is active
Hull accident ID 21 Collision with objects/animals Overturn/fall Not present in snapshot

Some Tejaratno disk files (including accident-causes, accident-report-type and inspection-place) contain authentication-error objects rather than codebook arrays. This does not establish the client's live codes; it establishes that the local cache is unusable and must be refreshed, not accepted as a lookup.

Infrastructure gaps

  1. lookups Mongo schema and reads/writes identify a codebook by name only. Parsian defaults to this unscoped DB source; notifier lookup paths also use it. Tenant-specific disk paths do not protect a cache populated from another tenant's DB row.
  2. getRemoteLookup accepts any non-null cache value, including API error objects. These prevent remote refresh and become empty rows in payload mapping.
  3. vehicle-kinds Mongo collection uses globally unique Id, with no client key. Search/approval can therefore validate against another tenant's catalogue.
  4. Vehicle-kind live sync calls fetchFromFanavaran with the generic definition URL directly. Tenant host rewriting occurs in getRemoteLookup, not in this direct-fetch path; Moallem can be sent to the generic host.
  5. Saved vehicle/stage reviews and remote person/policy caches do not uniformly record/verify the client/product before an explicit client-route submission.

Required completion order

  1. Scope persistent codebooks and vehicle-kind rows by client (and product or contract where the lookup requires it), with a migration/re-fetch strategy for existing unscoped data. Reject cached API-error objects.
  2. Preserve inquiry record provenance: exact policy vehicle/version for base claims; identity-matched damaged vehicle for GEN.12; policy-specific accessory IDs for hull expertise. Remove generic first-row guesses from these paths.
  3. Use current-client codebooks for explicit accident/review selections. The policy cannot supply accident cause, inspection location or damage severity. Resolve equivalent concepts by normalized meaning, never by reusing another client's numeric ID, and leave ambiguous choices for the expert.
  4. Validate every non-null code and its relationships at outbound time. Required unresolved/invalid codes should warn in preview and prevent the Fanavaran write, while existing best-effort handling preserves the local app workflow.
  5. Test clients with intentionally different IDs/captions and inactive rows, plus cache errors and wrong-client saved references. Then run read-only live inquiry checks per client before claiming end-to-end compatibility.

Source entry points

  • src/claim-request-management/claim-request-management.service.ts: base, damage, expertise and attachment builders; catalogue and lookup wrappers.
  • src/claim-request-management/fanavaran-accident-vehicle-used.ts: group-based default vehicle-use selection.
  • src/claim-request-management/fanavaran-hull-base-claim.ts: hull default codes.
  • src/claim-request-management/fanavaran-hull-expertise-lookups.ts: damage-kind defaults and existing accessory resolver.
  • src/claim-request-management/fanavaran-other-people.ts: person code mapping.
  • src/claim-request-management/fanavaran-stage-fields.ts: reviewed lookup fields.
  • src/fanavaran/fanavaran-lookup.service.ts: lookup cache/source resolution.
  • src/lookups/lookups.service.ts: shared Mongo persistence and vehicle-kind sync.
  • src/lookups/entities/schema/lookup.schema.ts and vehicle-kind.schema.ts: current unscoped storage models.
  • files/fanavaran-lookups/{moallem,tejaratno,parsian}/: inspected snapshots.