forked from Yara724/api
Add TejaratNo notifier review and submission validation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user