Files
SepehrYahyaee 83376df4ad feat: manage expert access and merge Parsian expert seeds
Allow role-specific identities and admin account activation, support national-code-only claim experts, and remove required voice from v4/v5. Add a combined, resumable Parsian seed that preserves existing accounts and merges locations and product codes.
2026-11-18 17:16:26 +03:30

3.7 KiB

Combined Parsian expert seed

The seed merges the original branches.json, file-reviewers.json, file-makers.json, the assessor records in field-experts.json, and the fixed remaining-experts.json. No Excel reader or generation step is needed.

Run from api/, using that API's .env:

npm run seed:parsian-all -- --dry-run
npm run seed:parsian-all

npm run seed:parsian-remaining runs the same combined seed, so the previous command also works. Use this combined seed instead of rerunning the old Tehran seed.

Combined source totals: 120 people, 50 branches, 88 claim experts, 88 file reviewers and 39 file makers. Actual inserts depend on the accounts/branches already in the database.

Merge rules:

  • A national code identifies a person; role + national code identifies an account. Existing account IDs, passwords, email/username aliases and activation states are retained. New accounts use national-code usernames and the hashed password 123321.
  • Existing primary branches stay unchanged. Additional source locations are merged and deduplicated into locations; differing branch lists no longer abort the import. This does not grant multiple primary branches in the application's branch-based authorization.
  • A new claim/reviewer counterpart inherits the existing counterpart's valid primary branch and assessment codes. File makers retain their own role-specific source locations.
  • Original JSON product codes take precedence over conflicting values in the remaining list. Existing database codes take precedence over imported values. Missing codes are filled; differing existing codes are kept and reported as merge notes, without stopping the batch.
  • Missing branches are created. Existing branch data is preserved, and missing details can be filled from the original directory. New branches without an address keep it blank. No address, contact or Fanavaran code is invented.
  • Ambiguous duplicate accounts, identities belonging to another insurer, incorrect stored roles, or unresolved primary branches are skipped with an explicit note. They are not silently moved, deleted or merged across insurers; the rest of the batch can continue.
  • No cases, case owners, signatures, SMS or Fanavaran requests are changed.

The reported reviewer ending 8521 remains at their existing primary branch and gains the additional source location. The assessment-code differences for the reviewer ending 8118 preserve existing/original codes rather than choosing the new conflicting values.

The historical field-experts.json contains assessor titles; those become claim experts + file reviewers, not FIELD_EXPERT accounts. Generic assessors are included without guessing product-specific codes. File-responsible / مسئول خسارت / ثبات titles create file makers only.

Excel row 37 remains excluded because its national code has 11 digits. The remaining source's skippedRows records it. National-code checksum warnings for rows 11, 26 and 27 retain the supplied ten-digit values for verification.

--dry-run performs reads only and prints planned creates, updates, skips and merge notes. Applying ensures the role identity indexes and sparse unique email indexes needed for email-less accounts, with a temporary uniqueness guard during legacy email-index replacement (MongoDB 5.0+). Keep the corresponding API changes supporting claim experts without email/mobile.

The seed is resumable. If an unexpected database/index error occurs, earlier successful writes remain. Conditional updates reject concurrent edits instead of overwriting them. Re-running merges the data again without resetting passwords or duplicating accounts.

Regression tests: node scripts/data/parsian-tehran/seed-remaining-experts.test.cjs.