location dynamicallllllly finally or not ?

This commit is contained in:
2026-11-11 15:07:19 +03:30
parent 5d84b9697f
commit d469cce463
5 changed files with 362 additions and 53 deletions
+20 -4
View File
@@ -1,4 +1,9 @@
import { ForbiddenException, Injectable, Logger } from "@nestjs/common";
import {
BadRequestException,
ForbiddenException,
Injectable,
Logger,
} from "@nestjs/common";
import {
FanavaranClientKey,
getFanavaranClientProfile,
@@ -45,11 +50,13 @@ export class FanavaranLocationService {
/**
* First staff candidate with a stored `locations[].id` wins.
* Fallback: tenant auth.location (lookups / cases with no staff locations).
* Tenant auth.location is allowed only when requireStaffLocation is false.
*/
async resolveBusinessLocation(input: {
clientKey: FanavaranClientKey;
staffCandidateIds?: Array<string | null | undefined>;
/** Claim submissions must never silently use a tenant-wide branch. */
requireStaffLocation?: boolean;
/** @deprecated Prefer staffCandidateIds — kept for older call sites. */
isMadeByFileMaker?: boolean;
fileMakerId?: string | null;
@@ -79,8 +86,17 @@ export class FanavaranLocationService {
}
}
this.logger.debug(
`Fanavaran Location fallback to tenant default → ${defaultLocation}`,
if (input.requireStaffLocation) {
throw new BadRequestException({
code: "FANAVARAN_STAFF_LOCATION_MISSING",
message:
"Cannot submit this claim to Fanavaran: no attached expert has a configured locations[].id (OpBUId). Configure the responsible staff member's location and retry.",
staffCandidateIds: [...seen],
});
}
this.logger.warn(
`[${input.clientKey}] Fanavaran Location fallback to tenant default=${defaultLocation}; no stored locations[].id found for staff candidates=${[...seen].join(",") || "none"}`,
);
return defaultLocation;
}