forked from Yara724/api
Compare commits
2
Commits
22ffeed75c
...
4302be8595
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4302be8595 | ||
|
|
64d5aa691f |
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
hasReviewedTejaratNotifier,
|
hasReviewedTejaratNotifier,
|
||||||
tejaratNotifierLookup,
|
isTejaratNotifierLookup,
|
||||||
} from "src/fanavaran/tejarat-notifier";
|
} from "src/fanavaran/tejarat-notifier";
|
||||||
import {
|
import {
|
||||||
BadGatewayException,
|
BadGatewayException,
|
||||||
@@ -187,6 +187,7 @@ import {
|
|||||||
fanavaranHullNestedClaimId,
|
fanavaranHullNestedClaimId,
|
||||||
toFanavaranHullBaseClaimPayload,
|
toFanavaranHullBaseClaimPayload,
|
||||||
} from "./fanavaran-hull-base-claim";
|
} from "./fanavaran-hull-base-claim";
|
||||||
|
import { toTejaratV15ThirdPartyBasePayload } from "./fanavaran-v15-third-party-base";
|
||||||
import {
|
import {
|
||||||
collectFanavaranExpertiseReadinessWarnings,
|
collectFanavaranExpertiseReadinessWarnings,
|
||||||
FANAVARAN_DEFAULT_HULL_REPAIR_DURATION,
|
FANAVARAN_DEFAULT_HULL_REPAIR_DURATION,
|
||||||
@@ -2335,6 +2336,64 @@ export class ClaimRequestManagementService {
|
|||||||
return parseJalaliDateParts(birthday);
|
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(
|
private async resolveDriverFanavaranId(
|
||||||
clientKey: FanavaranClientKey,
|
clientKey: FanavaranClientKey,
|
||||||
nationalCode: string | null | undefined,
|
nationalCode: string | null | undefined,
|
||||||
@@ -4309,6 +4368,26 @@ export class ClaimRequestManagementService {
|
|||||||
"baseClaim",
|
"baseClaim",
|
||||||
clientKey,
|
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 =
|
const fileRoleExpertIds =
|
||||||
@@ -5143,7 +5222,9 @@ export class ClaimRequestManagementService {
|
|||||||
fields: definitions.map((field) => {
|
fields: definitions.map((field) => {
|
||||||
const sent = fanavaranFieldStageSent(claim, field.stage);
|
const sent = fanavaranFieldStageSent(claim, field.stage);
|
||||||
const sentValue = sent
|
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;
|
: undefined;
|
||||||
const reviewedValue = claim.fanavaranFieldReview?.values?.[field.key];
|
const reviewedValue = claim.fanavaranFieldReview?.values?.[field.key];
|
||||||
const value = sentValue ?? reviewedValue ?? initial[field.key] ?? null;
|
const value = sentValue ?? reviewedValue ?? initial[field.key] ?? null;
|
||||||
@@ -5180,9 +5261,17 @@ export class ClaimRequestManagementService {
|
|||||||
clientKey: FanavaranClientKey,
|
clientKey: FanavaranClientKey,
|
||||||
name: string,
|
name: string,
|
||||||
): Promise<unknown[]> {
|
): Promise<unknown[]> {
|
||||||
if (clientKey === "tejaratno") {
|
if (clientKey === "tejaratno" && isTejaratNotifierLookup(name)) {
|
||||||
const supplied = tejaratNotifierLookup(name);
|
const stored = await this.fanavaranLookupService.readStoredLookup(name);
|
||||||
if (supplied) return supplied;
|
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);
|
const definition = this.fanavaranLookupDefinition(name);
|
||||||
try {
|
try {
|
||||||
@@ -5792,10 +5881,16 @@ export class ClaimRequestManagementService {
|
|||||||
return "Expert vehicle review is required before Fanavaran submission";
|
return "Expert vehicle review is required before Fanavaran submission";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clientKey = resolveFanavaranClientKey();
|
||||||
|
const notifierAllowed =
|
||||||
|
clientKey === "tejaratno"
|
||||||
|
? await this.tejaratNotifierAllowedIds(clientKey)
|
||||||
|
: undefined;
|
||||||
if (
|
if (
|
||||||
!hasReviewedTejaratNotifier(
|
!hasReviewedTejaratNotifier(
|
||||||
claimCase.fanavaranFieldReview?.values,
|
claimCase.fanavaranFieldReview?.values,
|
||||||
resolveFanavaranClientKey(),
|
clientKey,
|
||||||
|
notifierAllowed,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return "نوع و نسبت اعلامکننده باید پیش از ارسال اولیه پرونده به فناوران انتخاب شوند.";
|
return "نوع و نسبت اعلامکننده باید پیش از ارسال اولیه پرونده به فناوران انتخاب شوند.";
|
||||||
@@ -6882,8 +6977,16 @@ export class ClaimRequestManagementService {
|
|||||||
}
|
}
|
||||||
if (!existing) throw new NotFoundException("Claim case not found");
|
if (!existing) throw new NotFoundException("Claim case not found");
|
||||||
this.assertFanavaranVehicleReviewApproved(existing);
|
this.assertFanavaranVehicleReviewApproved(existing);
|
||||||
|
const notifierAllowed =
|
||||||
|
clientKey === "tejaratno"
|
||||||
|
? await this.tejaratNotifierAllowedIds(clientKey)
|
||||||
|
: undefined;
|
||||||
if (
|
if (
|
||||||
!hasReviewedTejaratNotifier(existing.fanavaranFieldReview?.values, clientKey)
|
!hasReviewedTejaratNotifier(
|
||||||
|
existing.fanavaranFieldReview?.values,
|
||||||
|
clientKey,
|
||||||
|
notifierAllowed,
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
throw new ConflictException({
|
throw new ConflictException({
|
||||||
code: "FANAVARAN_NOTIFIER_REVIEW_REQUIRED",
|
code: "FANAVARAN_NOTIFIER_REVIEW_REQUIRED",
|
||||||
|
|||||||
@@ -220,9 +220,13 @@ export function applyFanavaranStageFieldReview(
|
|||||||
): void {
|
): void {
|
||||||
const values = claim?.fanavaranFieldReview?.values;
|
const values = claim?.fanavaranFieldReview?.values;
|
||||||
if (clientKey === "tejaratno" && stage === "baseClaim") {
|
if (clientKey === "tejaratno" && stage === "baseClaim") {
|
||||||
|
const nested = claim?.fanavaranSync?.baseClaim?.lastPayload
|
||||||
|
?.DmgNotifications?.[0];
|
||||||
for (const key of Object.keys(TEJARAT_NOTIFIER_FIELDS)) {
|
for (const key of Object.keys(TEJARAT_NOTIFIER_FIELDS)) {
|
||||||
const value =
|
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.
|
// Preserve legacy submitted claims: adding fields must not overwrite unknown remote data.
|
||||||
if (value != null || !fanavaranFieldStageSent(claim, stage))
|
if (value != null || !fanavaranFieldStageSent(claim, stage))
|
||||||
payload[key] = value ?? null;
|
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;
|
||||||
|
}
|
||||||
@@ -54,7 +54,7 @@ export interface FanavaranPayloadDefaults {
|
|||||||
ClaimExpertId: number;
|
ClaimExpertId: number;
|
||||||
/**
|
/**
|
||||||
* GEN.08 expertise — کارشناس ارزیاب خسارت ثالث مالی / وکیل معتمد / کارشناس تحقیق
|
* GEN.08 expertise — کارشناس ارزیاب خسارت ثالث مالی / وکیل معتمد / کارشناس تحقیق
|
||||||
* (Parsian: 29; Tejaratno proven: 2709).
|
* (Parsian: 29; Tejaratno: 3709 کارشناس ارزیاب خسارت ثالث مالی).
|
||||||
*/
|
*/
|
||||||
ExpertiseClaimExpertId: number;
|
ExpertiseClaimExpertId: number;
|
||||||
/** GEN.06 hull RepairDuration when configured per tenant (optional). */
|
/** GEN.06 hull RepairDuration when configured per tenant (optional). */
|
||||||
@@ -121,9 +121,9 @@ export const SEED_FANAVARAN_CLIENT_PROFILES: Record<
|
|||||||
},
|
},
|
||||||
defaults: {
|
defaults: {
|
||||||
...SHARED_FANAVARAN_DEFAULTS,
|
...SHARED_FANAVARAN_DEFAULTS,
|
||||||
// GEN.03 — کارشناس مسئول پرونده مالی
|
// GEN.03 — کارشناس مسئول پرونده مالی (یارا ۷۲۴)
|
||||||
ClaimExpertId: 2721,
|
ClaimExpertId: 2721,
|
||||||
// GEN.08 — ارزیاب (proven successful submit 2026-07-18 ClaimExpertId: 2709)
|
// GEN.08 — کارشناس ارزیاب خسارت ثالث مالی (یارا ۷۲۴)
|
||||||
ExpertiseClaimExpertId: 2709,
|
ExpertiseClaimExpertId: 2709,
|
||||||
ClaimFileTypeId: 23,
|
ClaimFileTypeId: 23,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4025,6 +4025,25 @@ export class ExpertClaimService {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async tejaratNotifierAllowedIds(): Promise<
|
||||||
|
{ types: number[]; relations: number[] } | undefined
|
||||||
|
> {
|
||||||
|
if (resolveFanavaranClientKey() !== "tejaratno") return undefined;
|
||||||
|
const ids = (raw: unknown) =>
|
||||||
|
this.asFanavaranLookupRows(raw)
|
||||||
|
.map((row) => Number(row.Id))
|
||||||
|
.filter((id) => Number.isInteger(id) && id > 0);
|
||||||
|
try {
|
||||||
|
const [typesRaw, relationsRaw] = await Promise.all([
|
||||||
|
this.lookupsService.getClientRemoteLookup("notifier-type"),
|
||||||
|
this.lookupsService.getClientRemoteLookup("notifier-relation"),
|
||||||
|
]);
|
||||||
|
return { types: ids(typesRaw), relations: ids(relationsRaw) };
|
||||||
|
} catch {
|
||||||
|
return { types: [], relations: [] };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private activeFanavaranLookupRows(value: unknown) {
|
private activeFanavaranLookupRows(value: unknown) {
|
||||||
return this.asFanavaranLookupRows(value)
|
return this.asFanavaranLookupRows(value)
|
||||||
.filter((row) => row.IsActive !== 0 && Number(row.Id) > 0)
|
.filter((row) => row.IsActive !== 0 && Number(row.Id) > 0)
|
||||||
@@ -4111,6 +4130,7 @@ export class ExpertClaimService {
|
|||||||
!hasReviewedTejaratNotifier(
|
!hasReviewedTejaratNotifier(
|
||||||
fields?.review.values ?? claim.fanavaranFieldReview?.values,
|
fields?.review.values ?? claim.fanavaranFieldReview?.values,
|
||||||
resolveFanavaranClientKey(),
|
resolveFanavaranClientKey(),
|
||||||
|
await this.tejaratNotifierAllowedIds(),
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ function setup(product = "third-party", extra: any = {}) {
|
|||||||
service.claimRequestManagementService = management;
|
service.claimRequestManagementService = management;
|
||||||
service.lookupsService = {
|
service.lookupsService = {
|
||||||
getClientRemoteLookup: jest.fn().mockImplementation(async (name) => {
|
getClientRemoteLookup: jest.fn().mockImplementation(async (name) => {
|
||||||
|
const notifier = tejaratNotifierLookup(name);
|
||||||
|
if (notifier) return notifier;
|
||||||
if (name === "vehicle-groups") return [{ Id: 1, Caption: "سواری" }];
|
if (name === "vehicle-groups") return [{ Id: 1, Caption: "سواری" }];
|
||||||
if (name === "vehicle-use-types")
|
if (name === "vehicle-use-types")
|
||||||
return [{ Id: 1, Caption: "شخصی", VehicleGroupId: 1 }];
|
return [{ Id: 1, Caption: "شخصی", VehicleGroupId: 1 }];
|
||||||
|
|||||||
@@ -34,6 +34,13 @@ export class FanavaranLookupService {
|
|||||||
private readonly lookupModel: Model<LookupDocument>,
|
private readonly lookupModel: Model<LookupDocument>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
/** Stored `lookups` collection row. Does not call Fanavaran. */
|
||||||
|
async readStoredLookup(name: string): Promise<unknown | null> {
|
||||||
|
const doc = await this.lookupModel.findOne({ name }).lean().exec();
|
||||||
|
if (!doc) return null;
|
||||||
|
return (doc as { response?: unknown }).response ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
private cacheFilePath(clientKey: FanavaranClientKey, fileName: string): string {
|
private cacheFilePath(clientKey: FanavaranClientKey, fileName: string): string {
|
||||||
return join(fanavaranLookupCacheDir(clientKey), fileName);
|
return join(fanavaranLookupCacheDir(clientKey), fileName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export class FanavaranPayloadDefaultsEmbed {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* GEN.08 expertise — کارشناس ارزیاب خسارت ثالث مالی (or وکیل/تحقیق).
|
* GEN.08 expertise — کارشناس ارزیاب خسارت ثالث مالی (or وکیل/تحقیق).
|
||||||
* (Parsian example: 29; Tejaratno proven send: 2709).
|
* (Parsian example: 29; Tejaratno: 3709 کارشناس ارزیاب خسارت ثالث مالی).
|
||||||
*/
|
*/
|
||||||
@Prop({ type: Number, required: true })
|
@Prop({ type: Number, required: true })
|
||||||
ExpertiseClaimExpertId: number;
|
ExpertiseClaimExpertId: number;
|
||||||
|
|||||||
@@ -8,21 +8,23 @@ import {
|
|||||||
|
|
||||||
describe("TejaratNo notifier contract", () => {
|
describe("TejaratNo notifier contract", () => {
|
||||||
it.each(["notifier-type", "notifier-relation"])(
|
it.each(["notifier-type", "notifier-relation"])(
|
||||||
"exposes the supplied %s without querying Fanavaran or the database",
|
"reads %s from the lookups collection and does not call Fanavaran",
|
||||||
async (name) => {
|
async (name) => {
|
||||||
|
const stored = tejaratNotifierLookup(name);
|
||||||
const service = Object.create(LookupsService.prototype) as any;
|
const service = Object.create(LookupsService.prototype) as any;
|
||||||
service.activeClientKey = jest.fn().mockReturnValue("tejaratno");
|
service.activeClientKey = jest.fn().mockReturnValue("tejaratno");
|
||||||
service.fanavaranLookupService = { getRemoteLookup: jest.fn() };
|
service.fanavaranLookupService = {
|
||||||
service.lookupDbService = { findOne: jest.fn() };
|
getRemoteLookup: jest.fn(),
|
||||||
|
readStoredLookup: jest.fn().mockResolvedValue(stored),
|
||||||
|
};
|
||||||
const result = await service.getClientRemoteLookup(name);
|
const result = await service.getClientRemoteLookup(name);
|
||||||
expect(result).toEqual(tejaratNotifierLookup(name));
|
expect(result).toEqual(stored);
|
||||||
expect(result.every((row) => row.IsActive === 1 && row.Id !== 5518)).toBe(
|
expect(service.fanavaranLookupService.readStoredLookup).toHaveBeenCalledWith(
|
||||||
true,
|
name,
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
service.fanavaranLookupService.getRemoteLookup,
|
service.fanavaranLookupService.getRemoteLookup,
|
||||||
).not.toHaveBeenCalled();
|
).not.toHaveBeenCalled();
|
||||||
expect(service.lookupDbService.findOne).not.toHaveBeenCalled();
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -23,21 +23,32 @@ export const TEJARAT_NOTIFIER_FIELDS = {
|
|||||||
NotifierRelationId: "notifier-relation",
|
NotifierRelationId: "notifier-relation",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export function tejaratNotifierLookup(name: string) {
|
export function isTejaratNotifierLookup(
|
||||||
if (!Object.prototype.hasOwnProperty.call(TEJARAT_NOTIFIER_LOOKUPS, name))
|
name: string,
|
||||||
return undefined;
|
): name is keyof typeof TEJARAT_NOTIFIER_LOOKUPS {
|
||||||
return TEJARAT_NOTIFIER_LOOKUPS[
|
return Object.prototype.hasOwnProperty.call(TEJARAT_NOTIFIER_LOOKUPS, name);
|
||||||
name as keyof typeof TEJARAT_NOTIFIER_LOOKUPS
|
|
||||||
].map((row) => ({ ...row }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Both selections must be explicit, canonical numeric IDs; 5518 is excluded. */
|
export function tejaratNotifierLookup(name: string) {
|
||||||
|
if (!isTejaratNotifierLookup(name)) return undefined;
|
||||||
|
return TEJARAT_NOTIFIER_LOOKUPS[name].map((row) => ({ ...row }));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Both selections must be explicit numeric IDs from the allowed codebook. */
|
||||||
export function hasReviewedTejaratNotifier(
|
export function hasReviewedTejaratNotifier(
|
||||||
values: Record<string, unknown> | null | undefined,
|
values: Record<string, unknown> | null | undefined,
|
||||||
clientKey: FanavaranClientKey,
|
clientKey: FanavaranClientKey,
|
||||||
|
allowed?: { types?: number[]; relations?: number[] },
|
||||||
): boolean {
|
): boolean {
|
||||||
if (clientKey !== "tejaratno") return true;
|
if (clientKey !== "tejaratno") return true;
|
||||||
return Object.entries(TEJARAT_NOTIFIER_FIELDS).every(([key, lookup]) =>
|
const typeIds =
|
||||||
TEJARAT_NOTIFIER_LOOKUPS[lookup].some((row) => row.Id === values?.[key]),
|
allowed?.types ??
|
||||||
|
TEJARAT_NOTIFIER_LOOKUPS["notifier-type"].map((row) => row.Id);
|
||||||
|
const relationIds =
|
||||||
|
allowed?.relations ??
|
||||||
|
TEJARAT_NOTIFIER_LOOKUPS["notifier-relation"].map((row) => row.Id);
|
||||||
|
return (
|
||||||
|
typeIds.includes(values?.NotifierTypeId as number) &&
|
||||||
|
relationIds.includes(values?.NotifierRelationId as number)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -671,7 +671,7 @@ export class LookupsController {
|
|||||||
description:
|
description:
|
||||||
"Generic cached Fanavaran lookup fetcher. Configured names use their catalogue URL; " +
|
"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.",
|
"TejaratNo notifier-type and notifier-relation are read from the lookups collection and are not fetched from Fanavaran.",
|
||||||
})
|
})
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
name: "lookupName",
|
name: "lookupName",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { tejaratNotifierLookup } from "src/fanavaran/tejarat-notifier";
|
import { isTejaratNotifierLookup } from "src/fanavaran/tejarat-notifier";
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
Injectable,
|
Injectable,
|
||||||
@@ -126,12 +126,15 @@ export class LookupsService implements OnModuleInit, OnModuleDestroy {
|
|||||||
|
|
||||||
async getClientRemoteLookup(lookupName: string): Promise<unknown> {
|
async getClientRemoteLookup(lookupName: string): Promise<unknown> {
|
||||||
const clientKey = this.activeClientKey();
|
const clientKey = this.activeClientKey();
|
||||||
const notifier = tejaratNotifierLookup(lookupName);
|
if (isTejaratNotifierLookup(lookupName)) {
|
||||||
if (notifier) {
|
|
||||||
if (clientKey !== "tejaratno") {
|
if (clientKey !== "tejaratno") {
|
||||||
throw new BadRequestException("Notifier lookups apply only to TejaratNo.");
|
throw new BadRequestException("Notifier lookups apply only to TejaratNo.");
|
||||||
}
|
}
|
||||||
return notifier;
|
const stored = await this.fanavaranLookupService.readStoredLookup(lookupName);
|
||||||
|
if (stored == null) {
|
||||||
|
throw new NotFoundException(`Lookup "${lookupName}" not found`);
|
||||||
|
}
|
||||||
|
return stored;
|
||||||
}
|
}
|
||||||
const definition = this.findRemoteLookup(lookupName);
|
const definition = this.findRemoteLookup(lookupName);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user