fanavaran V15 tejaratno

This commit is contained in:
2026-10-10 16:04:07 +03:30
parent 22ffeed75c
commit 64d5aa691f
12 changed files with 279 additions and 33 deletions
@@ -34,6 +34,13 @@ export class FanavaranLookupService {
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 {
return join(fanavaranLookupCacheDir(clientKey), fileName);
}
@@ -53,7 +53,7 @@ export class FanavaranPayloadDefaultsEmbed {
/**
* GEN.08 expertise — کارشناس ارزیاب خسارت ثالث مالی (or وکیل/تحقیق).
* (Parsian example: 29; Tejaratno proven send: 2709).
* (Parsian example: 29; Tejaratno: 3709 کارشناس ارزیاب خسارت ثالث مالی).
*/
@Prop({ type: Number, required: true })
ExpertiseClaimExpertId: number;
+9 -7
View File
@@ -8,21 +8,23 @@ import {
describe("TejaratNo notifier contract", () => {
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) => {
const stored = tejaratNotifierLookup(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() };
service.fanavaranLookupService = {
getRemoteLookup: jest.fn(),
readStoredLookup: jest.fn().mockResolvedValue(stored),
};
const result = await service.getClientRemoteLookup(name);
expect(result).toEqual(tejaratNotifierLookup(name));
expect(result.every((row) => row.IsActive === 1 && row.Id !== 5518)).toBe(
true,
expect(result).toEqual(stored);
expect(service.fanavaranLookupService.readStoredLookup).toHaveBeenCalledWith(
name,
);
expect(
service.fanavaranLookupService.getRemoteLookup,
).not.toHaveBeenCalled();
expect(service.lookupDbService.findOne).not.toHaveBeenCalled();
},
);
+20 -9
View File
@@ -23,21 +23,32 @@ export const TEJARAT_NOTIFIER_FIELDS = {
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 }));
export function isTejaratNotifierLookup(
name: string,
): name is keyof typeof TEJARAT_NOTIFIER_LOOKUPS {
return Object.prototype.hasOwnProperty.call(TEJARAT_NOTIFIER_LOOKUPS, name);
}
/** 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(
values: Record<string, unknown> | null | undefined,
clientKey: FanavaranClientKey,
allowed?: { types?: number[]; relations?: number[] },
): 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]),
const typeIds =
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)
);
}