forked from Yara724/api
Add TejaratNo notifier review and submission validation
This commit is contained in:
@@ -9,6 +9,8 @@ The expert panel's existing Fanavaran review tab now includes accident and asses
|
||||
| AccidentLocationAddress | Both | Base claim | Non-empty address, up to 1,000 characters |
|
||||
| AccidentCityId | Both | Base claim | `cities` |
|
||||
| AccidentReportTypeId | Both | Base claim | `accident-report-type` |
|
||||
| NotifierTypeId | Both, **TejaratNo only** | Base claim | Supplied `notifier-type` IDs **5516 / 5517**; 5518 is excluded |
|
||||
| NotifierRelationId | Both, **TejaratNo only** | Base claim | Supplied `notifier-relation` IDs **5519–5526** |
|
||||
| DmgHistoryStatus | Third-party | Damage case | `dmg-history-status` (`dmg-case-history-status` upstream) |
|
||||
| InspectionPlaceId | Third-party | Expertise | `inspection-place` |
|
||||
| AccidentTypeId | Car-body | Base claim | `vehicle-hull-accident-types` |
|
||||
@@ -18,7 +20,17 @@ The expert panel's existing Fanavaran review tab now includes accident and asses
|
||||
| RepairDuration | Car-body | Expertise | Positive integer days |
|
||||
| VehicleCurrentValue | Car-body | Expertise | Positive integer **rials**, forwarded unchanged |
|
||||
|
||||
All seven lookup definitions already existed. Options use the deployment's active Fanavaran client and its existing live/cache lookup service. Only active canonical `Id` values are accepted; captions are resolved server-side. Array and nested `data` lookup envelopes are supported. Missing/empty lookups are shown as unavailable and cannot be replaced with guessed IDs.
|
||||
The seven original remote lookup definitions already existed. Options use the deployment's active Fanavaran client and its existing live/cache lookup service. Only active canonical `Id` values are accepted; captions are resolved server-side. Array and nested `data` lookup envelopes are supported. Missing/empty lookups are shown as unavailable and cannot be replaced with guessed IDs.
|
||||
|
||||
### TejaratNo notifier review
|
||||
|
||||
For the configured deployment tenant `tejaratno` (`FANAVARAN_CLIENT`, case-insensitive), the same tab shows **نوع اعلامکننده** and **نسبت اعلامکننده**. The API supplies and validates the tenant-provided IDs/captions directly; these two lists do not depend on a remote fetch or a guessed Fanavaran lookup URL. They are also available through the existing `GET /lookups/fanavaran/notifier-type` and `GET /lookups/fanavaran/notifier-relation` routes for this tenant. Other tenants cannot edit or request these tenant-specific fields.
|
||||
|
||||
Neither selection has a guessed default. Both must be saved before initial vehicle approval/initial Fanavaran submission. Initial combined approval saves the IDs, captions and history atomically. Missing or excluded values cannot bypass the rule through old clients or manual submission: manual initial submission returns `409` with `FANAVARAN_NOTIFIER_REVIEW_REQUIRED`; automatic submission skips until the fields are reviewed. Already approved, unsent claims can save them with the existing versioned field PATCH endpoint. Saving fields alone does not send a remote request.
|
||||
|
||||
The selections are sent as `NotifierTypeId` / `NotifierRelationId` on GEN.03 for both third-party and car-body claims. Hull filtering preserves them only for TejaratNo. They lock once the base stage is sent. Existing submitted claims remain usable without a migration; submitted notifier values are preserved on subsequent hull synchronization, and unknown legacy values are not overwritten with null.
|
||||
|
||||
The notifier payload property names follow the proposed contract; the tenant did not provide an upstream schema. Live Fanavaran acceptance must be verified in tenant QA. No remote writes are performed by regression tests.
|
||||
|
||||
`VehicleCurrentValue` can remain unset when no expert override exists, preserving the existing case-value/policy-value fallback. A stored override cannot be cleared with null or an empty string. This review does not change the application's other valuation fields or calculate price drop.
|
||||
|
||||
@@ -34,8 +46,8 @@ All seven lookup definitions already existed. Options use the deployment's activ
|
||||
|
||||
- `GET /v2/expert-claim/request/:id/fanavaran-stage-fields`: applicable field definitions, current/default/submitted values, captions, compact lookup rows and per-field editability. This read does not submit a claim or persist a preview.
|
||||
- `PATCH /v2/expert-claim/request/:id/fanavaran-stage-fields`: `{ values: { ...changedFields }, expectedVersion: 0, confirmed: true }`. Values must apply to the product and belong to an unsent stage. Stale versions or stages sent during validation return `409`.
|
||||
- Existing `PUT .../fanavaran-vehicle-review` additionally accepts optional `stageFields` and `stageFieldsVersion` for the initial combined approval. Older clients retain their existing behavior.
|
||||
- Existing `PUT .../fanavaran-vehicle-review` additionally accepts optional `stageFields` and `stageFieldsVersion` for the initial combined approval. Older clients retain their existing behavior for other tenants; TejaratNo requires the two notifier selections before initial approval.
|
||||
|
||||
Validated overrides and captions are stored in optional `claimCases.fanavaranFieldReview`, with version, reviewer and review timestamp. History events record before/after values and verified captions. Existing claims keep their existing defaults/fallbacks until reviewed; no migration or bulk data rewrite is required.
|
||||
|
||||
The review covers the eleven requested fields and the existing vehicle classification. It does not expose derived totals, provider identifiers, staff-role identifiers or every remaining field in the stage documents for arbitrary editing.
|
||||
The review covers the eleven original requested fields, the two TejaratNo-only notifier fields and the existing vehicle classification. It does not expose derived totals, provider identifiers, staff-role identifiers or every remaining field in the stage documents for arbitrary editing.
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
Snapshot of **what hull submit actually sends** after `toFanavaranHullBaseClaimPayload` / `toFanavaranHullExpertisePayload`.
|
||||
|
||||
TejaratNo additionally sends expert-reviewed `NotifierTypeId` and `NotifierRelationId` on the base claim, using the tenant-supplied codebooks. Both are required before initial submission; see [expert field review](../fanavaran-stage-field-review.md#tejaratno-notifier-review). Other tenants' bodies are unchanged.
|
||||
|
||||
|
||||
Experts can now review address, city, report type, accident/culprit/authority IDs, fault percentage, repair duration and vehicle value before their sending stage. See [expert field review](../fanavaran-stage-field-review.md); defaults below remain fallbacks for unreviewed records.
|
||||
|
||||
Staged flow (VHUD):
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
Snapshot of **what `ClaimRequestManagementService` actually sends** for `THIRD_PARTY` as of this version.
|
||||
|
||||
TejaratNo additionally sends expert-reviewed `NotifierTypeId` and `NotifierRelationId` on the base claim, using the tenant-supplied codebooks. Both are required before initial submission; see [expert field review](../fanavaran-stage-field-review.md#tejaratno-notifier-review). Other tenants' bodies are unchanged.
|
||||
|
||||
|
||||
Experts can now override address, city, report type, damage history and inspection place before their sending stage. See [expert field review](../fanavaran-stage-field-review.md); defaults below remain fallbacks for unreviewed records.
|
||||
|
||||
- Base: `POST /car/third-party-car-financial-claims` (GEN.03)
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
hasReviewedTejaratNotifier,
|
||||
tejaratNotifierLookup,
|
||||
} from "src/fanavaran/tejarat-notifier";
|
||||
import {
|
||||
BadGatewayException,
|
||||
BadRequestException,
|
||||
@@ -4287,9 +4291,10 @@ export class ClaimRequestManagementService {
|
||||
claimCase,
|
||||
"car-body",
|
||||
"baseClaim",
|
||||
clientKey,
|
||||
);
|
||||
delete payload.IsLicenseReplacement;
|
||||
const hull = toFanavaranHullBaseClaimPayload(payload);
|
||||
const hull = toFanavaranHullBaseClaimPayload(payload, clientKey);
|
||||
for (const key of Object.keys(payload)) delete payload[key];
|
||||
Object.assign(payload, hull);
|
||||
}
|
||||
@@ -4302,6 +4307,7 @@ export class ClaimRequestManagementService {
|
||||
claimCase,
|
||||
"third-party",
|
||||
"baseClaim",
|
||||
clientKey,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5092,7 +5098,7 @@ export class ClaimRequestManagementService {
|
||||
const product = fanavaranClaimProductFromBlameType(blame.type);
|
||||
const clientKey = resolveFanavaranClientKey();
|
||||
const defaults = getFanavaranClientProfile(clientKey).defaults;
|
||||
const definitions = fanavaranStageFields(product);
|
||||
const definitions = fanavaranStageFields(product, clientKey);
|
||||
const options = new Map<string, ReturnType<typeof activeStageLookupRows>>();
|
||||
await Promise.all(
|
||||
definitions
|
||||
@@ -5130,6 +5136,7 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
return {
|
||||
product,
|
||||
clientKey,
|
||||
version: claim.fanavaranFieldReview?.version ?? 0,
|
||||
reviewedAt: claim.fanavaranFieldReview?.reviewedAt,
|
||||
reviewedByActorName: claim.fanavaranFieldReview?.reviewedByActorName,
|
||||
@@ -5173,6 +5180,10 @@ export class ClaimRequestManagementService {
|
||||
clientKey: FanavaranClientKey,
|
||||
name: string,
|
||||
): Promise<unknown[]> {
|
||||
if (clientKey === "tejaratno") {
|
||||
const supplied = tejaratNotifierLookup(name);
|
||||
if (supplied) return supplied;
|
||||
}
|
||||
const definition = this.fanavaranLookupDefinition(name);
|
||||
try {
|
||||
const data = await this.fanavaranLookupService.getRemoteLookup(
|
||||
@@ -5781,6 +5792,15 @@ export class ClaimRequestManagementService {
|
||||
return "Expert vehicle review is required before Fanavaran submission";
|
||||
}
|
||||
|
||||
if (
|
||||
!hasReviewedTejaratNotifier(
|
||||
claimCase.fanavaranFieldReview?.values,
|
||||
resolveFanavaranClientKey(),
|
||||
)
|
||||
) {
|
||||
return "نوع و نسبت اعلامکننده باید پیش از ارسال اولیه پرونده به فناوران انتخاب شوند.";
|
||||
}
|
||||
|
||||
if (!claimCase.blameRequestId) {
|
||||
return "Blame case not linked to claim case";
|
||||
}
|
||||
@@ -5994,6 +6014,7 @@ export class ClaimRequestManagementService {
|
||||
built && typeof built === "object" && "payload" in built
|
||||
? (built as { payload: Record<string, unknown> }).payload
|
||||
: built,
|
||||
clientKey,
|
||||
);
|
||||
const url = `${fanavaranClaimsBaseUrl("car-body")}/${nestedId}`;
|
||||
this.logger.log(
|
||||
@@ -6861,6 +6882,15 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
if (!existing) throw new NotFoundException("Claim case not found");
|
||||
this.assertFanavaranVehicleReviewApproved(existing);
|
||||
if (
|
||||
!hasReviewedTejaratNotifier(existing.fanavaranFieldReview?.values, clientKey)
|
||||
) {
|
||||
throw new ConflictException({
|
||||
code: "FANAVARAN_NOTIFIER_REVIEW_REQUIRED",
|
||||
message:
|
||||
"نوع و نسبت اعلامکننده باید پیش از ارسال اولیه پرونده به فناوران بررسی و انتخاب شوند.",
|
||||
});
|
||||
}
|
||||
|
||||
const auditSession: FanavaranAuditSession = {
|
||||
trackingCode: this.fanavaranAuditService.generateTrackingCode(),
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import type { FanavaranClientKey } from "src/core/config/fanavaran-client.config";
|
||||
import { TEJARAT_NOTIFIER_FIELDS } from "src/fanavaran/tejarat-notifier";
|
||||
|
||||
/** GEN.03 VHUD input fields. Do not send ثالث-only keys (DamagedCount, HasOtherCulprit, plaques, …). */
|
||||
export const FANAVARAN_HULL_BASE_CLAIM_KEYS = [
|
||||
"ArchiveNo",
|
||||
@@ -120,6 +123,7 @@ export function customerIdFromHullPolicyRecord(
|
||||
|
||||
export function toFanavaranHullBaseClaimPayload(
|
||||
built: Record<string, unknown>,
|
||||
clientKey?: FanavaranClientKey,
|
||||
): Record<string, unknown> {
|
||||
const next: Record<string, unknown> = {};
|
||||
for (const key of FANAVARAN_HULL_BASE_CLAIM_KEYS) {
|
||||
@@ -167,6 +171,11 @@ export function toFanavaranHullBaseClaimPayload(
|
||||
? built[key]
|
||||
: null;
|
||||
}
|
||||
if (clientKey === "tejaratno") {
|
||||
for (const key of Object.keys(TEJARAT_NOTIFIER_FIELDS)) {
|
||||
if (Object.prototype.hasOwnProperty.call(built, key)) next[key] = built[key];
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { TEJARAT_NOTIFIER_FIELDS } from "src/fanavaran/tejarat-notifier";
|
||||
import type { FanavaranClaimProduct } from "./fanavaran-claim-product";
|
||||
import type { FanavaranClientKey } from "src/core/config/fanavaran-client.config";
|
||||
|
||||
export type FanavaranFieldStage = "baseClaim" | "damageCase" | "expertise";
|
||||
export type FanavaranFieldValues = Partial<
|
||||
@@ -15,7 +17,9 @@ export type FanavaranFieldKey =
|
||||
| "AuthorityCulpritId"
|
||||
| "CustomerFaultPercent"
|
||||
| "RepairDuration"
|
||||
| "VehicleCurrentValue";
|
||||
| "VehicleCurrentValue"
|
||||
| "NotifierTypeId"
|
||||
| "NotifierRelationId";
|
||||
|
||||
export interface FanavaranFieldReview {
|
||||
values: FanavaranFieldValues;
|
||||
@@ -37,6 +41,7 @@ export interface FanavaranStageFieldDefinition {
|
||||
max?: number;
|
||||
unit?: string;
|
||||
optional?: boolean;
|
||||
requiredBeforeSubmit?: boolean;
|
||||
}
|
||||
|
||||
const common: FanavaranStageFieldDefinition[] = [
|
||||
@@ -64,10 +69,34 @@ const common: FanavaranStageFieldDefinition[] = [
|
||||
|
||||
export function fanavaranStageFields(
|
||||
product: FanavaranClaimProduct,
|
||||
clientKey?: FanavaranClientKey,
|
||||
): FanavaranStageFieldDefinition[] {
|
||||
const baseFields: FanavaranStageFieldDefinition[] = [
|
||||
...common,
|
||||
...(clientKey === "tejaratno"
|
||||
? [
|
||||
{
|
||||
key: "NotifierTypeId" as const,
|
||||
label: "نوع اعلامکننده",
|
||||
stage: "baseClaim" as const,
|
||||
type: "lookup" as const,
|
||||
lookup: "notifier-type",
|
||||
requiredBeforeSubmit: true,
|
||||
},
|
||||
{
|
||||
key: "NotifierRelationId" as const,
|
||||
label: "نسبت اعلامکننده",
|
||||
stage: "baseClaim" as const,
|
||||
type: "lookup" as const,
|
||||
lookup: "notifier-relation",
|
||||
requiredBeforeSubmit: true,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
return product === "car-body"
|
||||
? [
|
||||
...common,
|
||||
...baseFields,
|
||||
{
|
||||
key: "AccidentTypeId",
|
||||
label: "نوع حادثه بدنه",
|
||||
@@ -117,7 +146,7 @@ export function fanavaranStageFields(
|
||||
},
|
||||
]
|
||||
: [
|
||||
...common,
|
||||
...baseFields,
|
||||
{
|
||||
key: "DmgHistoryStatus",
|
||||
label: "وضعیت سابقه خسارت",
|
||||
@@ -187,10 +216,20 @@ export function applyFanavaranStageFieldReview(
|
||||
claim: any,
|
||||
product: FanavaranClaimProduct,
|
||||
stage: FanavaranFieldStage,
|
||||
clientKey?: FanavaranClientKey,
|
||||
): void {
|
||||
const values = claim?.fanavaranFieldReview?.values;
|
||||
if (clientKey === "tejaratno" && stage === "baseClaim") {
|
||||
for (const key of Object.keys(TEJARAT_NOTIFIER_FIELDS)) {
|
||||
const value =
|
||||
values?.[key] ?? claim?.fanavaranSync?.baseClaim?.lastPayload?.[key];
|
||||
// Preserve legacy submitted claims: adding fields must not overwrite unknown remote data.
|
||||
if (value != null || !fanavaranFieldStageSent(claim, stage))
|
||||
payload[key] = value ?? null;
|
||||
}
|
||||
}
|
||||
if (!values) return;
|
||||
for (const field of fanavaranStageFields(product)) {
|
||||
for (const field of fanavaranStageFields(product, clientKey)) {
|
||||
const value = values[field.key];
|
||||
if (field.stage === stage && value != null) payload[field.key] = value;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Type } from "class-transformer";
|
||||
import {
|
||||
Equals,
|
||||
IsInt,
|
||||
IsIn,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Max,
|
||||
@@ -12,6 +13,26 @@ import {
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
|
||||
export class FanavaranStageFieldValuesDto {
|
||||
@ApiPropertyOptional({
|
||||
enum: [5516, 5517],
|
||||
description:
|
||||
"TejaratNo only: notifier type; required before initial submission",
|
||||
})
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@IsIn([5516, 5517])
|
||||
NotifierTypeId?: number;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
enum: [5519, 5520, 5521, 5522, 5523, 5524, 5525, 5526],
|
||||
description:
|
||||
"TejaratNo only: notifier relation; required before initial submission",
|
||||
})
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@IsIn([5519, 5520, 5521, 5522, 5523, 5524, 5525, 5526])
|
||||
NotifierRelationId?: number;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
import { hasReviewedTejaratNotifier } from "src/fanavaran/tejarat-notifier";
|
||||
import { resolveFanavaranClientKey } from "src/core/config/fanavaran-client.config";
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
ConflictException,
|
||||
@@ -4104,6 +4107,16 @@ export class ExpertClaimService {
|
||||
actor,
|
||||
)
|
||||
: undefined;
|
||||
if (
|
||||
!hasReviewedTejaratNotifier(
|
||||
fields?.review.values ?? claim.fanavaranFieldReview?.values,
|
||||
resolveFanavaranClientKey(),
|
||||
)
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
"نوع و نسبت اعلامکننده را پیش از تایید و ارسال پرونده انتخاب کنید.",
|
||||
);
|
||||
}
|
||||
const [groupsRaw, useTypesRaw, systemsRaw, vehicleKind] = await Promise.all(
|
||||
[
|
||||
this.lookupsService.getClientRemoteLookup("vehicle-groups"),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tejaratNotifierLookup } from "src/fanavaran/tejarat-notifier";
|
||||
import {
|
||||
BadRequestException,
|
||||
ConflictException,
|
||||
@@ -38,6 +39,8 @@ function setup(product = "third-party", extra: any = {}) {
|
||||
management.getFanavaranLookupRows = jest
|
||||
.fn()
|
||||
.mockImplementation(async (_client, name) => {
|
||||
const notifier = tejaratNotifierLookup(name);
|
||||
if (notifier) return notifier;
|
||||
const ids = {
|
||||
cities: 702,
|
||||
"accident-report-type": 156,
|
||||
@@ -65,11 +68,9 @@ function setup(product = "third-party", extra: any = {}) {
|
||||
const service = Object.create(ExpertClaimService.prototype) as any;
|
||||
service.getClaimDetailV2 = jest.fn().mockResolvedValue({});
|
||||
service.blameRequestDbService = {
|
||||
findById: jest
|
||||
.fn()
|
||||
.mockResolvedValue({
|
||||
type: product === "car-body" ? "CAR_BODY" : "THIRD_PARTY",
|
||||
}),
|
||||
findById: jest.fn().mockResolvedValue({
|
||||
type: product === "car-body" ? "CAR_BODY" : "THIRD_PARTY",
|
||||
}),
|
||||
};
|
||||
service.claimCaseDbService = {
|
||||
findById: jest.fn().mockResolvedValue(claim),
|
||||
@@ -87,22 +88,33 @@ function setup(product = "third-party", extra: any = {}) {
|
||||
return [{ Id: 1, Caption: "شخصی", VehicleGroupId: 1 }];
|
||||
return [{ Id: 14, Caption: "پراید", VehicleGroupId: 1 }];
|
||||
}),
|
||||
getActiveVehicleKindById: jest
|
||||
.fn()
|
||||
.mockResolvedValue({
|
||||
Id: 7456,
|
||||
Caption: "پراید",
|
||||
VehicleGroupId: 1,
|
||||
VehicleSystemId: 14,
|
||||
}),
|
||||
getActiveVehicleKindById: jest.fn().mockResolvedValue({
|
||||
Id: 7456,
|
||||
Caption: "پراید",
|
||||
VehicleGroupId: 1,
|
||||
VehicleSystemId: 14,
|
||||
}),
|
||||
};
|
||||
return { service, management, claim };
|
||||
}
|
||||
|
||||
describe("Expert Fanavaran stage fields", () => {
|
||||
it.each(["third-party", "car-body"])(
|
||||
"puts reviewed base fields into the actual %s preview after derived/default enrichment",
|
||||
async (product) => {
|
||||
const originalClient = process.env.FANAVARAN_CLIENT;
|
||||
beforeEach(() => {
|
||||
process.env.FANAVARAN_CLIENT = "parsian";
|
||||
});
|
||||
afterEach(() => {
|
||||
if (originalClient === undefined) delete process.env.FANAVARAN_CLIENT;
|
||||
else process.env.FANAVARAN_CLIENT = originalClient;
|
||||
});
|
||||
it.each([
|
||||
["third-party", "parsian"],
|
||||
["car-body", "parsian"],
|
||||
["third-party", "tejaratno"],
|
||||
["car-body", "tejaratno"],
|
||||
] as const)(
|
||||
"puts reviewed base fields into the actual %s/%s preview after derived/default enrichment",
|
||||
async (product, clientKey) => {
|
||||
const { management, claim } = setup(product, {
|
||||
fanavaranFieldReview: {
|
||||
values: {
|
||||
@@ -113,6 +125,8 @@ describe("Expert Fanavaran stage fields", () => {
|
||||
CulpritTypeId: 301,
|
||||
AuthorityCulpritId: 8,
|
||||
CustomerFaultPercent: 0,
|
||||
NotifierTypeId: 5517,
|
||||
NotifierRelationId: 5523,
|
||||
},
|
||||
},
|
||||
fanavaranVehicleReview: { vehicleUseType: { id: 1 } },
|
||||
@@ -127,13 +141,11 @@ describe("Expert Fanavaran stage fields", () => {
|
||||
findByIdAndUpdate: jest.fn(),
|
||||
};
|
||||
management.blameRequestDbService = {
|
||||
findById: jest
|
||||
.fn()
|
||||
.mockResolvedValue({
|
||||
type: product === "car-body" ? "CAR_BODY" : "THIRD_PARTY",
|
||||
parties: [{ role: "FIRST" }],
|
||||
createdAt: new Date(),
|
||||
}),
|
||||
findById: jest.fn().mockResolvedValue({
|
||||
type: product === "car-body" ? "CAR_BODY" : "THIRD_PARTY",
|
||||
parties: [{ role: "FIRST" }],
|
||||
createdAt: new Date(),
|
||||
}),
|
||||
};
|
||||
management.resolveAccidentVehicleUsedFromApis = jest
|
||||
.fn()
|
||||
@@ -147,7 +159,7 @@ describe("Expert Fanavaran stage fields", () => {
|
||||
payload.CustomerFaultPercent = 100;
|
||||
payload.AuthorityCulpritId = 1;
|
||||
});
|
||||
const payload = await management.previewFanavaranSubmitV2(id, "parsian", {
|
||||
const payload = await management.previewFanavaranSubmitV2(id, clientKey, {
|
||||
persistPayload: false,
|
||||
forceRefreshPolicy: false,
|
||||
});
|
||||
@@ -156,6 +168,15 @@ describe("Expert Fanavaran stage fields", () => {
|
||||
AccidentCityId: 702,
|
||||
AccidentReportTypeId: 156,
|
||||
});
|
||||
if (clientKey === "tejaratno")
|
||||
expect(payload).toMatchObject({
|
||||
NotifierTypeId: 5517,
|
||||
NotifierRelationId: 5523,
|
||||
});
|
||||
else {
|
||||
expect(payload).not.toHaveProperty("NotifierTypeId");
|
||||
expect(payload).not.toHaveProperty("NotifierRelationId");
|
||||
}
|
||||
if (product === "car-body") {
|
||||
expect(payload).toMatchObject({
|
||||
AccidentTypeId: 4,
|
||||
@@ -491,4 +512,257 @@ describe("Expert Fanavaran stage fields", () => {
|
||||
});
|
||||
expect(fanavaranStageFields("third-party")).toHaveLength(5);
|
||||
});
|
||||
it.each(["third-party", "car-body"])(
|
||||
"shows only the supplied TejaratNo notifier options for %s",
|
||||
async (product) => {
|
||||
process.env.FANAVARAN_CLIENT = "TejaratNo";
|
||||
const { service } = setup(product);
|
||||
const context = await service.getFanavaranStageFieldsV2(id, actor);
|
||||
expect(context.clientKey).toBe("tejaratno");
|
||||
const fields = context.fields.filter((field) =>
|
||||
field.key.startsWith("Notifier"),
|
||||
);
|
||||
expect(fields.map((field) => field.key)).toEqual([
|
||||
"NotifierTypeId",
|
||||
"NotifierRelationId",
|
||||
]);
|
||||
expect(
|
||||
fields.every(
|
||||
(field) =>
|
||||
field.value === null &&
|
||||
field.editable &&
|
||||
field.requiredBeforeSubmit,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(fields[0].options.map((row) => row.Id).sort()).toEqual([
|
||||
5516, 5517,
|
||||
]);
|
||||
expect(fields[1].options.map((row) => row.Id).sort()).toEqual([
|
||||
5519, 5520, 5521, 5522, 5523, 5524, 5525, 5526,
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["parsian", "moallem"])(
|
||||
"hides and rejects notifier edits for %s",
|
||||
async (tenant) => {
|
||||
process.env.FANAVARAN_CLIENT = tenant;
|
||||
const { service } = setup();
|
||||
const context = await service.getFanavaranStageFieldsV2(id, actor);
|
||||
expect(
|
||||
context.fields.some((field) => field.key.startsWith("Notifier")),
|
||||
).toBe(false);
|
||||
await expect(
|
||||
service.updateFanavaranStageFieldsV2(
|
||||
id,
|
||||
{
|
||||
values: { NotifierTypeId: 5516 },
|
||||
expectedVersion: 0,
|
||||
confirmed: true,
|
||||
},
|
||||
actor,
|
||||
),
|
||||
).rejects.toBeInstanceOf(BadRequestException);
|
||||
expect(
|
||||
service.claimCaseDbService.findOneAndUpdate,
|
||||
).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ NotifierTypeId: 5518 },
|
||||
{ NotifierTypeId: 5519 },
|
||||
{ NotifierRelationId: 5516 },
|
||||
{ NotifierRelationId: 5527 },
|
||||
{ NotifierTypeId: "5516" },
|
||||
{ NotifierRelationId: null },
|
||||
])("rejects excluded or invalid notifier values: %j", async (values) => {
|
||||
process.env.FANAVARAN_CLIENT = "tejaratno";
|
||||
const { service } = setup();
|
||||
await expect(
|
||||
service.updateFanavaranStageFieldsV2(
|
||||
id,
|
||||
{ values, expectedVersion: 0, confirmed: true },
|
||||
actor,
|
||||
),
|
||||
).rejects.toBeInstanceOf(BadRequestException);
|
||||
expect(service.claimCaseDbService.findOneAndUpdate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("persists notifier IDs, captions and audit history with the existing version guard", async () => {
|
||||
process.env.FANAVARAN_CLIENT = "tejaratno";
|
||||
const { service, claim } = setup();
|
||||
await service.updateFanavaranStageFieldsV2(
|
||||
id,
|
||||
{
|
||||
values: { NotifierTypeId: 5516, NotifierRelationId: 5521 },
|
||||
expectedVersion: 0,
|
||||
confirmed: true,
|
||||
},
|
||||
actor,
|
||||
);
|
||||
expect(claim.fanavaranFieldReview).toMatchObject({
|
||||
values: { NotifierTypeId: 5516, NotifierRelationId: 5521 },
|
||||
captions: { NotifierTypeId: "آسيب ديده", NotifierRelationId: "مالک" },
|
||||
version: 1,
|
||||
});
|
||||
const [filter, update] =
|
||||
service.claimCaseDbService.findOneAndUpdate.mock.calls[0];
|
||||
expect(filter.$and).toContainEqual({
|
||||
claimId: null,
|
||||
"fanavaranSync.baseClaim.claimId": null,
|
||||
"fanavaranSync.baseClaim.status": { $ne: "success" },
|
||||
});
|
||||
expect(update.$push.history.metadata.after).toMatchObject({
|
||||
NotifierTypeId: 5516,
|
||||
NotifierRelationId: 5521,
|
||||
});
|
||||
});
|
||||
|
||||
it("saves both notifier choices atomically before combined approval starts submission", async () => {
|
||||
process.env.FANAVARAN_CLIENT = "tejaratno";
|
||||
const { service, claim, management } = setup();
|
||||
await service.approveFanavaranVehicleReviewV2(
|
||||
id,
|
||||
{
|
||||
...vehicleBody,
|
||||
stageFieldsVersion: 0,
|
||||
stageFields: { NotifierTypeId: 5517, NotifierRelationId: 5526 },
|
||||
},
|
||||
actor,
|
||||
);
|
||||
expect(claim.fanavaranFieldReview.values).toMatchObject({
|
||||
NotifierTypeId: 5517,
|
||||
NotifierRelationId: 5526,
|
||||
});
|
||||
expect(
|
||||
management.autoSubmitToFanavaranV2OnClaimCreated,
|
||||
).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it.each([undefined, { NotifierTypeId: 5516 }, { NotifierRelationId: 5523 }])(
|
||||
"does not approve a TejaratNo vehicle with incomplete notifier selection: %j",
|
||||
async (stageFields) => {
|
||||
process.env.FANAVARAN_CLIENT = "tejaratno";
|
||||
const { service, management } = setup();
|
||||
await expect(
|
||||
service.approveFanavaranVehicleReviewV2(
|
||||
id,
|
||||
{ ...vehicleBody, stageFieldsVersion: 0, stageFields },
|
||||
actor,
|
||||
),
|
||||
).rejects.toBeInstanceOf(BadRequestException);
|
||||
expect(
|
||||
service.claimCaseDbService.findOneAndUpdate,
|
||||
).not.toHaveBeenCalled();
|
||||
expect(
|
||||
management.autoSubmitToFanavaranV2OnClaimCreated,
|
||||
).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
it("locks notifier fields after initial submission and shows the submitted selection", async () => {
|
||||
process.env.FANAVARAN_CLIENT = "tejaratno";
|
||||
const { service } = setup("third-party", {
|
||||
claimId: 10,
|
||||
fanavaranSync: {
|
||||
baseClaim: {
|
||||
lastPayload: { NotifierTypeId: 5517, NotifierRelationId: 5523 },
|
||||
},
|
||||
},
|
||||
});
|
||||
const context = await service.getFanavaranStageFieldsV2(id, actor);
|
||||
expect(
|
||||
context.fields.find((field) => field.key === "NotifierTypeId"),
|
||||
).toMatchObject({
|
||||
editable: false,
|
||||
value: 5517,
|
||||
source: "submitted",
|
||||
caption: "مقصر حادثه",
|
||||
});
|
||||
await expect(
|
||||
service.updateFanavaranStageFieldsV2(
|
||||
id,
|
||||
{
|
||||
values: { NotifierTypeId: 5516 },
|
||||
expectedVersion: 0,
|
||||
confirmed: true,
|
||||
},
|
||||
actor,
|
||||
),
|
||||
).rejects.toBeInstanceOf(ConflictException);
|
||||
});
|
||||
|
||||
it("blocks manual initial submission without notifier review before remote work", async () => {
|
||||
const { management, claim } = setup("third-party", {
|
||||
fanavaranVehicleReview: {
|
||||
approved: true,
|
||||
vehicleGroup: { id: 1 },
|
||||
vehicleUseType: { id: 1 },
|
||||
vehicleSystem: { id: 14 },
|
||||
vehicleKind: { id: 7456 },
|
||||
},
|
||||
});
|
||||
management.logger = { log: jest.fn() };
|
||||
management.claimCaseDbService = {
|
||||
findById: jest.fn().mockResolvedValue(claim),
|
||||
};
|
||||
management.previewFanavaranSubmitV2 = jest.fn();
|
||||
await expect(
|
||||
management.executeFanavaranV2Submit(id, "tejaratno"),
|
||||
).rejects.toMatchObject({
|
||||
response: { code: "FANAVARAN_NOTIFIER_REVIEW_REQUIRED" },
|
||||
});
|
||||
expect(management.previewFanavaranSubmitV2).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("soft-skips automatic TejaratNo submission until both choices are saved", async () => {
|
||||
process.env.FANAVARAN_CLIENT = "tejaratno";
|
||||
const { management, claim } = setup("third-party", {
|
||||
fanavaranVehicleReview: { approved: true },
|
||||
});
|
||||
management.blameRequestDbService = {
|
||||
findById: jest.fn().mockResolvedValue({ type: "THIRD_PARTY" }),
|
||||
};
|
||||
expect(await management.getFanavaranAutoSubmitSkipReason(claim)).toContain(
|
||||
"اعلامکننده",
|
||||
);
|
||||
claim.fanavaranFieldReview = {
|
||||
values: { NotifierTypeId: 5516, NotifierRelationId: 5519 },
|
||||
};
|
||||
expect(await management.getFanavaranAutoSubmitSkipReason(claim)).toBeNull();
|
||||
delete claim.fanavaranFieldReview;
|
||||
claim.claimId = 10;
|
||||
expect(await management.getFanavaranAutoSubmitSkipReason(claim)).toBe(
|
||||
"Already submitted to Fanavaran",
|
||||
);
|
||||
});
|
||||
|
||||
it("reuses notifier selections from a submitted base payload and preserves legacy records without them", () => {
|
||||
const payload = {};
|
||||
applyFanavaranStageFieldReview(
|
||||
payload,
|
||||
{
|
||||
claimId: 10,
|
||||
fanavaranSync: {
|
||||
baseClaim: {
|
||||
lastPayload: { NotifierTypeId: 5517, NotifierRelationId: 5523 },
|
||||
},
|
||||
},
|
||||
},
|
||||
"car-body",
|
||||
"baseClaim",
|
||||
"tejaratno",
|
||||
);
|
||||
expect(payload).toEqual({ NotifierTypeId: 5517, NotifierRelationId: 5523 });
|
||||
const legacy = {};
|
||||
applyFanavaranStageFieldReview(
|
||||
legacy,
|
||||
{ claimId: 10 },
|
||||
"car-body",
|
||||
"baseClaim",
|
||||
"tejaratno",
|
||||
);
|
||||
expect(legacy).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,6 +57,14 @@ function makeService(overrides?: { kind?: typeof kind }) {
|
||||
}
|
||||
|
||||
describe("Fanavaran vehicle review", () => {
|
||||
const originalClient = process.env.FANAVARAN_CLIENT;
|
||||
beforeEach(() => {
|
||||
process.env.FANAVARAN_CLIENT = "parsian";
|
||||
});
|
||||
afterEach(() => {
|
||||
if (originalClient === undefined) delete process.env.FANAVARAN_CLIENT;
|
||||
else process.env.FANAVARAN_CLIENT = originalClient;
|
||||
});
|
||||
it("persists an authoritative snapshot and releases deferred submission", async () => {
|
||||
const service = makeService();
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import { BadRequestException } from "@nestjs/common";
|
||||
import { LookupsService } from "src/lookups/lookups.service";
|
||||
import { toFanavaranHullBaseClaimPayload } from "src/claim-request-management/fanavaran-hull-base-claim";
|
||||
import {
|
||||
hasReviewedTejaratNotifier,
|
||||
tejaratNotifierLookup,
|
||||
} from "./tejarat-notifier";
|
||||
|
||||
describe("TejaratNo notifier contract", () => {
|
||||
it.each(["notifier-type", "notifier-relation"])(
|
||||
"exposes the supplied %s without querying Fanavaran or the database",
|
||||
async (name) => {
|
||||
const service = Object.create(LookupsService.prototype) as any;
|
||||
service.activeClientKey = jest.fn().mockReturnValue("tejaratno");
|
||||
service.fanavaranLookupService = { getRemoteLookup: jest.fn() };
|
||||
service.lookupDbService = { findOne: jest.fn() };
|
||||
const result = await service.getClientRemoteLookup(name);
|
||||
expect(result).toEqual(tejaratNotifierLookup(name));
|
||||
expect(result.every((row) => row.IsActive === 1 && row.Id !== 5518)).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
service.fanavaranLookupService.getRemoteLookup,
|
||||
).not.toHaveBeenCalled();
|
||||
expect(service.lookupDbService.findOne).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["parsian", "moallem"])(
|
||||
"rejects the tenant-specific lookups for %s",
|
||||
async (clientKey) => {
|
||||
const service = Object.create(LookupsService.prototype) as any;
|
||||
service.activeClientKey = jest.fn().mockReturnValue(clientKey);
|
||||
await expect(
|
||||
service.getClientRemoteLookup("notifier-type"),
|
||||
).rejects.toBeInstanceOf(BadRequestException);
|
||||
},
|
||||
);
|
||||
|
||||
it("does not expose prototype properties as lookup lists", () => {
|
||||
expect(tejaratNotifierLookup("__proto__")).toBeUndefined();
|
||||
expect(tejaratNotifierLookup("toString")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("requires explicit, allowed numeric choices only for TejaratNo", () => {
|
||||
expect(hasReviewedTejaratNotifier(undefined, "parsian")).toBe(true);
|
||||
expect(hasReviewedTejaratNotifier(undefined, "moallem")).toBe(true);
|
||||
expect(hasReviewedTejaratNotifier(undefined, "tejaratno")).toBe(false);
|
||||
expect(
|
||||
hasReviewedTejaratNotifier({ NotifierTypeId: 5516 }, "tejaratno"),
|
||||
).toBe(false);
|
||||
expect(
|
||||
hasReviewedTejaratNotifier(
|
||||
{ NotifierTypeId: 5518, NotifierRelationId: 5519 },
|
||||
"tejaratno",
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
hasReviewedTejaratNotifier(
|
||||
{ NotifierTypeId: "5516", NotifierRelationId: 5519 },
|
||||
"tejaratno",
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
hasReviewedTejaratNotifier(
|
||||
{ NotifierTypeId: 5517, NotifierRelationId: 5526 },
|
||||
"tejaratno",
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("preserves notifier fields in TejaratNo hull payloads without adding them for other tenants", () => {
|
||||
const input = {
|
||||
PolicyId: 12,
|
||||
NotifierTypeId: 5516,
|
||||
NotifierRelationId: 5521,
|
||||
};
|
||||
expect(toFanavaranHullBaseClaimPayload(input, "tejaratno")).toMatchObject(
|
||||
input,
|
||||
);
|
||||
for (const tenant of ["parsian", "moallem"] as const) {
|
||||
const payload = toFanavaranHullBaseClaimPayload(input, tenant);
|
||||
expect(payload).not.toHaveProperty("NotifierTypeId");
|
||||
expect(payload).not.toHaveProperty("NotifierRelationId");
|
||||
}
|
||||
expect(
|
||||
toFanavaranHullBaseClaimPayload({ PolicyId: 12 }, "tejaratno"),
|
||||
).not.toHaveProperty("NotifierTypeId");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { FanavaranClientKey } from "src/core/config/fanavaran-client.config";
|
||||
|
||||
/** Tenant-supplied codebooks. No unverified remote lookup paths or inferred IDs. */
|
||||
export const TEJARAT_NOTIFIER_LOOKUPS = {
|
||||
"notifier-type": [
|
||||
{ Caption: "آسيب ديده", Id: 5516, IsActive: 1 },
|
||||
{ Caption: "مقصر حادثه", Id: 5517, IsActive: 1 },
|
||||
],
|
||||
"notifier-relation": [
|
||||
{ Caption: "آسيب ديده", Id: 5519, IsActive: 1 },
|
||||
{ Caption: "نماينده آسيب ديده", Id: 5520, IsActive: 1 },
|
||||
{ Caption: "مالک", Id: 5521, IsActive: 1 },
|
||||
{ Caption: "بيمه گذار", Id: 5522, IsActive: 1 },
|
||||
{ Caption: "راننده", Id: 5523, IsActive: 1 },
|
||||
{ Caption: "نماينده راننده", Id: 5524, IsActive: 1 },
|
||||
{ Caption: "نماينده بيمه گذار", Id: 5525, IsActive: 1 },
|
||||
{ Caption: "نماينده مالک", Id: 5526, IsActive: 1 },
|
||||
],
|
||||
} as const;
|
||||
|
||||
export const TEJARAT_NOTIFIER_FIELDS = {
|
||||
NotifierTypeId: "notifier-type",
|
||||
NotifierRelationId: "notifier-relation",
|
||||
} as const;
|
||||
|
||||
export function tejaratNotifierLookup(name: string) {
|
||||
if (!Object.prototype.hasOwnProperty.call(TEJARAT_NOTIFIER_LOOKUPS, name))
|
||||
return undefined;
|
||||
return TEJARAT_NOTIFIER_LOOKUPS[
|
||||
name as keyof typeof TEJARAT_NOTIFIER_LOOKUPS
|
||||
].map((row) => ({ ...row }));
|
||||
}
|
||||
|
||||
/** Both selections must be explicit, canonical numeric IDs; 5518 is excluded. */
|
||||
export function hasReviewedTejaratNotifier(
|
||||
values: Record<string, unknown> | null | undefined,
|
||||
clientKey: FanavaranClientKey,
|
||||
): boolean {
|
||||
if (clientKey !== "tejaratno") return true;
|
||||
return Object.entries(TEJARAT_NOTIFIER_FIELDS).every(([key, lookup]) =>
|
||||
TEJARAT_NOTIFIER_LOOKUPS[lookup].some((row) => row.Id === values?.[key]),
|
||||
);
|
||||
}
|
||||
@@ -670,7 +670,8 @@ export class LookupsController {
|
||||
summary: "Fetch a Fanavaran remote lookup by name",
|
||||
description:
|
||||
"Generic cached Fanavaran lookup fetcher. Configured names use their catalogue URL; " +
|
||||
"unlisted slugs (e.g. vehicle-groups) fall back to car/base-info/{lookupName}.",
|
||||
"unlisted slugs (e.g. vehicle-groups) fall back to car/base-info/{lookupName}. " +
|
||||
"TejaratNo notifier-type and notifier-relation use the supplied local tenant codebooks without a remote fetch.",
|
||||
})
|
||||
@ApiParam({
|
||||
name: "lookupName",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tejaratNotifierLookup } from "src/fanavaran/tejarat-notifier";
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
@@ -125,6 +126,13 @@ export class LookupsService implements OnModuleInit, OnModuleDestroy {
|
||||
|
||||
async getClientRemoteLookup(lookupName: string): Promise<unknown> {
|
||||
const clientKey = this.activeClientKey();
|
||||
const notifier = tejaratNotifierLookup(lookupName);
|
||||
if (notifier) {
|
||||
if (clientKey !== "tejaratno") {
|
||||
throw new BadRequestException("Notifier lookups apply only to TejaratNo.");
|
||||
}
|
||||
return notifier;
|
||||
}
|
||||
const definition = this.findRemoteLookup(lookupName);
|
||||
|
||||
// Parsian: file → lookups collection → Fanavaran (default inside FanavaranLookupService)
|
||||
|
||||
Reference in New Issue
Block a user