forked from Yara724/api
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.
80 lines
8.7 KiB
Markdown
80 lines
8.7 KiB
Markdown
# Insurer, staff and branch management
|
|
|
|
The expert panel now supports setting up a fresh deployment without creating insurer/staff accounts through Swagger. No existing case, assignment, Fanavaran or reporting routes were removed.
|
|
|
|
## Starting with only a super-admin
|
|
|
|
1. Sign in through the existing super-admin login.
|
|
2. Open **شرکتهای بیمه** (`/insurers`), and add the Persian/English insurer names, numeric client code and expert collaboration mode.
|
|
3. Add a **حساب بیمه** with name, email and password. This creates an existing `company` actor attached to that insurer; its login identifier is its email.
|
|
4. Use the insurer's **شعبهها** and **اعضا** actions to select the insurer and create branches and staff.
|
|
5. The insurer's own account can manage its branches and all six staff roles. It cannot create or edit insurers or insurer login accounts.
|
|
|
|
The **مدیریت** tabs in `/branches` and `/expert-list` provide creation and editing. Existing date/search filters and performance tables remain under **آمار عملکرد**. The super-admin's existing insurer selector remains available.
|
|
|
|
## API surface
|
|
|
|
All endpoints require bearer authentication and strictly validate their DTOs. Swagger groups are `super-admin-management` and `insurer-management`.
|
|
|
|
| Operation | Super-admin | Insurer |
|
|
| --- | --- | --- |
|
|
| List/create insurers | `GET/POST /super-admin/management/clients` | Unavailable |
|
|
| Edit insurer metadata | `PATCH /super-admin/management/clients/:id` | Unavailable |
|
|
| List/create insurer login accounts | `GET/POST /super-admin/management/clients/:clientId/accounts` | Unavailable |
|
|
| Edit insurer login account | `PATCH /super-admin/management/clients/:clientId/accounts/:id` | Unavailable |
|
|
| List/create staff | `GET/POST /super-admin/management/staff?clientId=...` | `GET/POST /expert-insurer/management/staff` |
|
|
| Edit staff | `PATCH /super-admin/management/staff/:role/:id?clientId=...` | `PATCH /expert-insurer/management/staff/:role/:id` |
|
|
| Activate/deactivate a staff role account | `PATCH /super-admin/management/staff/:role/:id/status?clientId=...` | Unavailable |
|
|
| List/create branches | `GET/POST /super-admin/management/branches?clientId=...` | `GET/POST /expert-insurer/management/branches` |
|
|
| Edit branch | `PATCH /super-admin/management/branches/:id?clientId=...` | `PATCH /expert-insurer/management/branches/:id` |
|
|
|
|
Staff list queries accept `search`, `role`, `page` and `limit` (default 20, capped at 100). Responses contain `list`, `total`, `page` and `limit`. Branch responses contain `list`; clients contain `clients`. Account lists share the staff pagination contract.
|
|
|
|
## Fields
|
|
|
|
`role` is one of `expert`, `damage_expert`, `field_expert`, `file_maker`, `file_reviewer`, or `call_center`, and is selected only during creation. These use the existing collections and actor login mechanism.
|
|
|
|
Staff creation requires `firstName`, `lastName`, a ten-digit `nationalCode` and a password of at least six characters. Email and mobile are optional for claim experts, field experts, file makers, file reviewers and call-center agents, matching the seed format. Blame experts still require email and mobile. Seed-style accounts without email log in using their national code. National-code and email aliases can be reused across different roles; they remain unique within a role because login has no tenant selector. Create each required role with the same credentials to let one person use several flows. Existing records and passwords are preserved. The remaining-experts seed prepares sparse email indexes for older claim-expert databases before inserting email-less accounts.
|
|
|
|
Staff lists include `isActive`, treating older records with no flag as active. Only super-admins can change this flag using the status endpoint and a boolean body, e.g. `{"isActive": false}`. Disabled accounts cannot log in or reuse existing JWTs. Status belongs to the selected role account; the same person's other assignments are unaffected. See [expert access and optional voice](expert-access-and-optional-voice.md).
|
|
|
|
Common optional properties are `branchId`, `phone`, `mobile`, `email`, `city`, `state`, `address` and `expertCode`. A branch, when supplied, must belong to the account's insurer. `expertCode` and the role-specific Fanavaran IDs are positive integer strings, matching existing persistence and mapping contracts.
|
|
|
|
| Role | Additional optional fields |
|
|
| --- | --- |
|
|
| Blame, claim and field expert | All four Fanavaran codes below, plus `locations` |
|
|
| FileMaker | `ThirdPartyClaimExpertId`, `CarBodyClaimExpertId`, `locations` |
|
|
| FileReviewer | `ThirdPartyExpertiseClaim`, `CarBodyExpertiseClaim`, `locations` |
|
|
| Call-center agent | None of the four product/stage codes |
|
|
|
|
| Field | Persian label in the panel |
|
|
| --- | --- |
|
|
| `ThirdPartyClaimExpertId` | کارشناس مسئول پرونده مالی |
|
|
| `CarBodyClaimExpertId` | کارشناس مسئول پرونده بدنه |
|
|
| `ThirdPartyExpertiseClaim` | کارشناس ارزیاب خسارت ثالث مالی |
|
|
| `CarBodyExpertiseClaim` | کارشناس ارزیاب خسارت بدنه |
|
|
|
|
All four codes are optional, editable and clearable for blame, claim and field experts. FileMaker accounts accept only the first two, FileReviewer accounts accept only the last two, and call-center accounts reject all four through the API. The panel presents these four named fields rather than the legacy generic `expertCode` input; existing `expertCode` values are preserved.
|
|
|
|
`locations` is an editable array of `{id, name}`. Both properties must be nonempty, and IDs must be unique within the array. These are Fanavaran OpBUId / HTTP `Location` values. Claim submissions prefer the responsible staff member's primary `locations[].id` (file-maker, file-reviewer, field, blame, or damage expert) for all tenants. When that array is missing, null, or empty, the integration loads the staff member's branch using `branchId` and uses `branches.code`. It checks this branch fallback before moving to another staff candidate. If no candidate supplies a staff location or branch code, submission reports `FANAVARAN_STAFF_LOCATION_MISSING` instead of sending the tenant default. Shared staff locations still participate in Parsian FileMaker/FileReviewer matching; management does not alter that matching logic.
|
|
|
|
Branches require `code`, `name`, `city`, `state`, and `address`. `fullName`, `phoneNumber`, `isActive` (default true) and `activityStartDate` are optional and editable. Branch codes remain unique within an insurer. Insurer login accounts support name, email, password and optional contact/address fields; their role and tenant are assigned by the server.
|
|
|
|
PATCH sends only changed fields. Omit `password` to preserve it; supply a replacement to change it. Nullable optional staff properties can be cleared with `null`; send `locations: []` to clear locations. Required identity and branch properties cannot be cleared. The form preserves the full stored activity timestamp when its date is unchanged.
|
|
|
|
## Access and compatibility
|
|
|
|
- An insurer's scope is taken from the authenticated actor's `clientKey`. A supplied tenant identifier never overrides it.
|
|
- Super-admin changes require an existing selected insurer. Foreign branch IDs and cross-tenant account/branch edits are rejected. The tenant predicate is retained on the final atomic update.
|
|
- Staff roles, client association, arbitrary fields and MongoDB update operators cannot be edited through these endpoints.
|
|
- Passwords are hashed through the existing `HashService`; passwords, OTPs, tokens and insurer SMS credentials are excluded from management responses.
|
|
- Existing client settings and integrations are preserved when editing client metadata. This UI does not replace the existing system/settings or inquiry configuration screens.
|
|
- Existing insurer-create DTOs also accept `expertCode` and the four Fanavaran codes, restricted to the applicable fields for FileMaker/FileReviewer DTOs. The branch schema and existing create DTO accept `fullName`.
|
|
- No migration, deletion, mass reassignment or change to case workflow is required.
|
|
|
|
## Verification
|
|
|
|
`npm test -- --runInBand` includes schema-backed management tests for all six roles, optional seed fields, role-specific IDs, locations, tenant isolation, branch updates, account passwords, protected fields and strict DTO validation. The route contract retains the existing routes and records the additional super-admin status endpoint. HTTP tests cover cross-role login, activation, status permissions, and rejection of existing sessions after deactivation.
|
|
|
|
The expert UI's `npm run test:ui` includes management proxy and payload regression checks. Desktop/mobile browser checks use mocked local API responses, rather than modifying a real insurer. Live credential login, database indexes under concurrent writes and outbound Fanavaran submission remain integration QA responsibilities.
|