lookups query and api call fixed

This commit is contained in:
2026-10-24 15:10:55 +03:30
parent 8d73d4996c
commit 69a9fc351c
6 changed files with 63 additions and 35 deletions
+1 -1
View File
@@ -671,7 +671,7 @@ export class LookupsController {
description:
"Generic cached Fanavaran lookup fetcher. Configured names use their catalogue URL; " +
"unlisted slugs (e.g. vehicle-groups) fall back to car/base-info/{lookupName}. " +
"TejaratNo notifier-type and notifier-relation are read from the lookups collection and are not fetched from Fanavaran.",
"Notifier lookups check the lookups collection first for every tenant, then fetch from Fanavaran on a miss.",
})
@ApiParam({
name: "lookupName",
+5 -15
View File
@@ -136,30 +136,20 @@ export class LookupsService implements OnModuleInit, OnModuleDestroy {
async getClientRemoteLookup(lookupName: string): Promise<unknown> {
const clientKey = this.activeClientKey();
if (isTejaratNotifierLookup(lookupName)) {
if (clientKey !== "tejaratno") {
throw new BadRequestException("Notifier lookups apply only to TejaratNo.");
}
const stored = await this.fanavaranLookupService.readStoredLookup(lookupName);
if (stored == null) {
throw new NotFoundException(`Lookup "${lookupName}" not found`);
}
return stored;
}
const definition = this.findRemoteLookup(lookupName);
// Parsian: file → lookups collection → Fanavaran (default inside FanavaranLookupService)
// Tejaratno: file → Fanavaran → DB on API failure
// readStoredLookup returns null when the row is missing, so a Fanavaran
// failure is not replaced by "Lookup not found".
// Notifier lookups check the shared DB seed before Fanavaran for every
// tenant. A DB miss proceeds to Fanavaran and the response is cached below.
// Other lookups retain their configured tenant-specific fallback order.
const data = await this.fanavaranLookupService.getRemoteLookup(
clientKey,
definition.url,
definition.cacheFile,
clientKey === "tejaratno"
isTejaratNotifierLookup(lookupName)
? {
dbSource: () =>
this.fanavaranLookupService.readStoredLookup(lookupName),
preferDbBeforeRemote: true,
}
: undefined,
);