forked from Yara724/api
fanavaran V15 tejaratno
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user