Files
yara724api/src/fanavaran/tejarat-notifier.ts
T
2026-10-10 16:04:07 +03:30

55 lines
2.1 KiB
TypeScript

import type { FanavaranClientKey } from "src/core/config/fanavaran-client.config";
/** Tenant-supplied codebooks. No unverified remote lookup paths or inferred IDs. */
export const TEJARAT_NOTIFIER_LOOKUPS = {
"notifier-type": [
{ Caption: "آسيب ديده", Id: 5516, IsActive: 1 },
{ Caption: "مقصر حادثه", Id: 5517, IsActive: 1 },
],
"notifier-relation": [
{ Caption: "آسيب ديده", Id: 5519, IsActive: 1 },
{ Caption: "نماينده آسيب ديده", Id: 5520, IsActive: 1 },
{ Caption: "مالک", Id: 5521, IsActive: 1 },
{ Caption: "بيمه گذار", Id: 5522, IsActive: 1 },
{ Caption: "راننده", Id: 5523, IsActive: 1 },
{ Caption: "نماينده راننده", Id: 5524, IsActive: 1 },
{ Caption: "نماينده بيمه گذار", Id: 5525, IsActive: 1 },
{ Caption: "نماينده مالک", Id: 5526, IsActive: 1 },
],
} as const;
export const TEJARAT_NOTIFIER_FIELDS = {
NotifierTypeId: "notifier-type",
NotifierRelationId: "notifier-relation",
} as const;
export function isTejaratNotifierLookup(
name: string,
): name is keyof typeof TEJARAT_NOTIFIER_LOOKUPS {
return Object.prototype.hasOwnProperty.call(TEJARAT_NOTIFIER_LOOKUPS, name);
}
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;
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)
);
}