forked from Yara724/api
fanavaran V15 tejaratno
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
hasReviewedTejaratNotifier,
|
||||
tejaratNotifierLookup,
|
||||
isTejaratNotifierLookup,
|
||||
} from "src/fanavaran/tejarat-notifier";
|
||||
import {
|
||||
BadGatewayException,
|
||||
@@ -187,6 +187,7 @@ import {
|
||||
fanavaranHullNestedClaimId,
|
||||
toFanavaranHullBaseClaimPayload,
|
||||
} from "./fanavaran-hull-base-claim";
|
||||
import { toTejaratV15ThirdPartyBasePayload } from "./fanavaran-v15-third-party-base";
|
||||
import {
|
||||
collectFanavaranExpertiseReadinessWarnings,
|
||||
FANAVARAN_DEFAULT_HULL_REPAIR_DURATION,
|
||||
@@ -2335,6 +2336,64 @@ export class ClaimRequestManagementService {
|
||||
return parseJalaliDateParts(birthday);
|
||||
}
|
||||
|
||||
private async tejaratNotifierAllowedIds(
|
||||
clientKey: FanavaranClientKey,
|
||||
): Promise<{ types: number[]; relations: number[] }> {
|
||||
const [types, relations] = await Promise.all([
|
||||
this.getFanavaranLookupRows(clientKey, "notifier-type"),
|
||||
this.getFanavaranLookupRows(clientKey, "notifier-relation"),
|
||||
]);
|
||||
const ids = (rows: unknown[]) =>
|
||||
rows
|
||||
.map((row) => Number((row as { Id?: unknown })?.Id))
|
||||
.filter((id) => Number.isInteger(id) && id > 0);
|
||||
return { types: ids(types), relations: ids(relations) };
|
||||
}
|
||||
|
||||
/**
|
||||
* V15 GEN.03 announcer: guilty insurer, RoleId 161 then 166.
|
||||
* Missing people are registered with GEN.44 (mobile comes from the user profile).
|
||||
*/
|
||||
private async resolveTejaratNotifierPartyId(input: {
|
||||
clientKey: FanavaranClientKey;
|
||||
blameCase: {
|
||||
parties?: Array<{ person?: any }>;
|
||||
expert?: { decision?: { guiltyPartyId?: unknown } };
|
||||
};
|
||||
claimCaseId?: string;
|
||||
}): Promise<number | null> {
|
||||
const parties = input.blameCase.parties ?? [];
|
||||
const guiltyPartyId = this.resolveGuiltyPartyIdV2(
|
||||
parties as any,
|
||||
input.blameCase.expert?.decision?.guiltyPartyId as any,
|
||||
);
|
||||
const guilty = parties.find(
|
||||
(party) =>
|
||||
String(party?.person?.userId ?? "") === String(guiltyPartyId ?? ""),
|
||||
);
|
||||
const person = guilty?.person;
|
||||
const nationalCode =
|
||||
pickPersonNationalCode(person) ??
|
||||
this.getNationalCodeOfInsurerForGuiltyPartyV2(
|
||||
parties as any,
|
||||
guiltyPartyId as any,
|
||||
);
|
||||
const birthday = pickPersonBirthday(person);
|
||||
const existing = await this.resolveDriverFanavaranId(
|
||||
input.clientKey,
|
||||
nationalCode,
|
||||
birthday,
|
||||
true,
|
||||
);
|
||||
if (existing != null) return existing;
|
||||
if (!person) return null;
|
||||
return this.registerFanavaranOtherPerson({
|
||||
clientKey: input.clientKey,
|
||||
person,
|
||||
claimCaseId: input.claimCaseId,
|
||||
});
|
||||
}
|
||||
|
||||
private async resolveDriverFanavaranId(
|
||||
clientKey: FanavaranClientKey,
|
||||
nationalCode: string | null | undefined,
|
||||
@@ -4309,6 +4368,26 @@ export class ClaimRequestManagementService {
|
||||
"baseClaim",
|
||||
clientKey,
|
||||
);
|
||||
if (clientKey === "tejaratno") {
|
||||
const notifierPartyId = await this.resolveTejaratNotifierPartyId({
|
||||
clientKey,
|
||||
blameCase,
|
||||
claimCaseId,
|
||||
});
|
||||
if (requirePolicyId && notifierPartyId == null) {
|
||||
throw new ConflictException({
|
||||
code: "FANAVARAN_NOTIFIER_PARTY_REQUIRED",
|
||||
message:
|
||||
"اعلامکننده خسارت در فناوران پیدا نشد. کد ملی، تاریخ تولد و موبایل بیمهگذار مقصر برای ثبت شخص لازم است.",
|
||||
});
|
||||
}
|
||||
const v15 = toTejaratV15ThirdPartyBasePayload(
|
||||
payload,
|
||||
notifierPartyId,
|
||||
);
|
||||
for (const key of Object.keys(payload)) delete payload[key];
|
||||
Object.assign(payload, v15);
|
||||
}
|
||||
}
|
||||
|
||||
const fileRoleExpertIds =
|
||||
@@ -5143,7 +5222,9 @@ export class ClaimRequestManagementService {
|
||||
fields: definitions.map((field) => {
|
||||
const sent = fanavaranFieldStageSent(claim, field.stage);
|
||||
const sentValue = sent
|
||||
? claim.fanavaranSync?.[field.stage]?.lastPayload?.[field.key]
|
||||
? (claim.fanavaranSync?.[field.stage]?.lastPayload?.[field.key] ??
|
||||
claim.fanavaranSync?.[field.stage]?.lastPayload
|
||||
?.DmgNotifications?.[0]?.[field.key])
|
||||
: undefined;
|
||||
const reviewedValue = claim.fanavaranFieldReview?.values?.[field.key];
|
||||
const value = sentValue ?? reviewedValue ?? initial[field.key] ?? null;
|
||||
@@ -5180,9 +5261,17 @@ export class ClaimRequestManagementService {
|
||||
clientKey: FanavaranClientKey,
|
||||
name: string,
|
||||
): Promise<unknown[]> {
|
||||
if (clientKey === "tejaratno") {
|
||||
const supplied = tejaratNotifierLookup(name);
|
||||
if (supplied) return supplied;
|
||||
if (clientKey === "tejaratno" && isTejaratNotifierLookup(name)) {
|
||||
const stored = await this.fanavaranLookupService.readStoredLookup(name);
|
||||
let rows: unknown = stored;
|
||||
for (
|
||||
let level = 0;
|
||||
level < 3 && rows && !Array.isArray(rows) && typeof rows === "object";
|
||||
level++
|
||||
) {
|
||||
rows = (rows as { data?: unknown }).data;
|
||||
}
|
||||
return Array.isArray(rows) ? rows : [];
|
||||
}
|
||||
const definition = this.fanavaranLookupDefinition(name);
|
||||
try {
|
||||
@@ -5792,10 +5881,16 @@ export class ClaimRequestManagementService {
|
||||
return "Expert vehicle review is required before Fanavaran submission";
|
||||
}
|
||||
|
||||
const clientKey = resolveFanavaranClientKey();
|
||||
const notifierAllowed =
|
||||
clientKey === "tejaratno"
|
||||
? await this.tejaratNotifierAllowedIds(clientKey)
|
||||
: undefined;
|
||||
if (
|
||||
!hasReviewedTejaratNotifier(
|
||||
claimCase.fanavaranFieldReview?.values,
|
||||
resolveFanavaranClientKey(),
|
||||
clientKey,
|
||||
notifierAllowed,
|
||||
)
|
||||
) {
|
||||
return "نوع و نسبت اعلامکننده باید پیش از ارسال اولیه پرونده به فناوران انتخاب شوند.";
|
||||
@@ -6882,8 +6977,16 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
if (!existing) throw new NotFoundException("Claim case not found");
|
||||
this.assertFanavaranVehicleReviewApproved(existing);
|
||||
const notifierAllowed =
|
||||
clientKey === "tejaratno"
|
||||
? await this.tejaratNotifierAllowedIds(clientKey)
|
||||
: undefined;
|
||||
if (
|
||||
!hasReviewedTejaratNotifier(existing.fanavaranFieldReview?.values, clientKey)
|
||||
!hasReviewedTejaratNotifier(
|
||||
existing.fanavaranFieldReview?.values,
|
||||
clientKey,
|
||||
notifierAllowed,
|
||||
)
|
||||
) {
|
||||
throw new ConflictException({
|
||||
code: "FANAVARAN_NOTIFIER_REVIEW_REQUIRED",
|
||||
|
||||
Reference in New Issue
Block a user