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",
|
||||
|
||||
@@ -220,9 +220,13 @@ export function applyFanavaranStageFieldReview(
|
||||
): void {
|
||||
const values = claim?.fanavaranFieldReview?.values;
|
||||
if (clientKey === "tejaratno" && stage === "baseClaim") {
|
||||
const nested = claim?.fanavaranSync?.baseClaim?.lastPayload
|
||||
?.DmgNotifications?.[0];
|
||||
for (const key of Object.keys(TEJARAT_NOTIFIER_FIELDS)) {
|
||||
const value =
|
||||
values?.[key] ?? claim?.fanavaranSync?.baseClaim?.lastPayload?.[key];
|
||||
values?.[key] ??
|
||||
claim?.fanavaranSync?.baseClaim?.lastPayload?.[key] ??
|
||||
nested?.[key];
|
||||
// Preserve legacy submitted claims: adding fields must not overwrite unknown remote data.
|
||||
if (value != null || !fanavaranFieldStageSent(claim, stage))
|
||||
payload[key] = value ?? null;
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* TejaratNo third-party GEN.03 (package V15.00).
|
||||
* Same keys the flow UI writes for FANAVARAN_API_VERSION=v15:
|
||||
* AnnouncementDate and the extra v14 nulls are omitted, and the announcer
|
||||
* goes in DmgNotifications rather than on the claim root.
|
||||
*/
|
||||
|
||||
const V15_BASE_KEYS = [
|
||||
"AccidentCityId",
|
||||
"AccidentReportTypeId",
|
||||
"AccidentVehicleUsedId",
|
||||
"ClaimExpertId",
|
||||
"CompensationReferenceId",
|
||||
"CulpritLicenceTypeId",
|
||||
"CulpritTypeId",
|
||||
"AccidentCauseId",
|
||||
"AccidentDate",
|
||||
"DocReceivedDate",
|
||||
"AccidentTime",
|
||||
"AccidentLocationAddress",
|
||||
"EstimateAmount",
|
||||
"AccidentCulpritId",
|
||||
"CouponNo",
|
||||
"CourtArchiveNo",
|
||||
"CulpritLicenceCityId",
|
||||
"CulpritLicenceCountryId",
|
||||
"CulpritLicenceForeignCityName",
|
||||
"CulpritLicenceIssuDate",
|
||||
"CulpritLicenceNo",
|
||||
"DamagedCount",
|
||||
"DmgAssessorFirstCreationTime",
|
||||
"EntryDate",
|
||||
"IsLicenseMatchWithVehicleKind",
|
||||
"HasOtherCulprit",
|
||||
"IsAccidentOutOfBorder",
|
||||
"IsFatalAccident",
|
||||
"IsPlaqueChanged",
|
||||
"PlaqueCityId",
|
||||
"PlaqueKindId",
|
||||
"PlaqueLeftNo",
|
||||
"PlaqueMiddleCodeId",
|
||||
"PlaqueNo",
|
||||
"PlaqueRightNo",
|
||||
"PlaqueSampleId",
|
||||
"PlaqueSerial",
|
||||
"PoliceOfficerId",
|
||||
"PoliceReportDesc",
|
||||
"PoliceReportSeri",
|
||||
"PoliceReportSerial",
|
||||
"PolicyId",
|
||||
"PreviousPolicyEndDate",
|
||||
"TrackingCode",
|
||||
"IsLicenseReplacement",
|
||||
"UnknownCulpritCauseId",
|
||||
] as const;
|
||||
|
||||
function positiveId(value: unknown): number | null {
|
||||
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
||||
if (typeof value === "string" && /^\d+$/.test(value.trim())) {
|
||||
const parsed = Number(value.trim());
|
||||
return parsed > 0 ? parsed : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function toTejaratV15ThirdPartyBasePayload(
|
||||
source: Record<string, unknown>,
|
||||
notifierPartyId: number | null,
|
||||
): Record<string, unknown> {
|
||||
const payload: Record<string, unknown> = {};
|
||||
for (const key of V15_BASE_KEYS) {
|
||||
payload[key] = source[key] === undefined ? null : source[key];
|
||||
}
|
||||
const accidentDate =
|
||||
typeof source.AccidentDate === "string" && source.AccidentDate.trim()
|
||||
? source.AccidentDate
|
||||
: null;
|
||||
payload.DmgNotifications = [
|
||||
{
|
||||
LetterNo: null,
|
||||
ClaimNotificationDate: accidentDate,
|
||||
LetterDate: accidentDate,
|
||||
InjuredCount: null,
|
||||
DeathCount: null,
|
||||
Desc: null,
|
||||
NotifierTypeId: positiveId(source.NotifierTypeId),
|
||||
NotifierRelationId: positiveId(source.NotifierRelationId),
|
||||
NotifierPartyId: notifierPartyId,
|
||||
IsInjuredPartyIdentified: null,
|
||||
InjuredPartyId: null,
|
||||
},
|
||||
];
|
||||
return payload;
|
||||
}
|
||||
Reference in New Issue
Block a user