fanavaran duplication request problems fixed.

This commit is contained in:
2026-08-02 17:00:19 +03:30
parent c2f5c576fa
commit b345818d43
9 changed files with 884 additions and 123 deletions

View File

@@ -1,20 +1,26 @@
export type FanavaranClientKey = "parsian" | "tejaratno";
export type FanavaranClientKey = "parsian" | "tejaratno" | "moallem";
export const FANAVARAN_CLIENT_KEYS: readonly FanavaranClientKey[] = [
"parsian",
"tejaratno",
"moallem",
] as const;
/** Swagger `@ApiParam({ enum })` value — keep in sync with {@link FANAVARAN_CLIENT_KEYS}. */
export const FANAVARAN_CLIENT_SWAGGER_ENUM: FanavaranClientKey[] = [
...FANAVARAN_CLIENT_KEYS,
];
export function isFanavaranClientKey(
value: string,
): value is FanavaranClientKey {
const normalized = value?.trim().toLowerCase();
return normalized === "parsian" || normalized === "tejaratno";
return (FANAVARAN_CLIENT_KEYS as readonly string[]).includes(normalized);
}
export function normalizeFanavaranClientKey(value: string): FanavaranClientKey {
const normalized = value?.trim().toLowerCase();
if (normalized === "parsian" || normalized === "tejaratno") {
if (isFanavaranClientKey(normalized)) {
return normalized;
}
throw new Error(
@@ -56,6 +62,29 @@ export interface FanavaranClientProfile {
defaults: FanavaranPayloadDefaults;
}
/**
* Shared codebook-ish defaults used when a tenant has not supplied its own
* ClaimExpertId / plaque ids yet. Moallem auth is real; ClaimExpertId may need
* a Moallem-specific value from Fanavaran lookups after first deploy.
*/
const SHARED_FANAVARAN_DEFAULTS: FanavaranPayloadDefaults = {
AccidentCityId: 701,
AccidentReportTypeId: 155,
AccidentVehicleUsedId: 1,
ClaimExpertId: 4543092,
ExpertiseClaimExpertId: 4543092,
CompensationReferenceId: 167,
CulpritLicenceTypeId: 2,
CulpritTypeId: 337,
DmgCaseTypeId: 175,
DmgHistoryStatus: 5214,
PlaqueKindId: 8,
PlaqueSampleId: 10,
DriverIsOwner: 0,
FaultPercent: 100,
ClaimFileTypeId: 23,
};
const FANAVARAN_CLIENT_PROFILES: Record<
FanavaranClientKey,
FanavaranClientProfile
@@ -72,20 +101,9 @@ const FANAVARAN_CLIENT_PROFILES: Record<
location: "100",
},
defaults: {
AccidentCityId: 701,
AccidentReportTypeId: 155,
AccidentVehicleUsedId: 1,
...SHARED_FANAVARAN_DEFAULTS,
ClaimExpertId: 4543092,
ExpertiseClaimExpertId: 4543092,
CompensationReferenceId: 167,
CulpritLicenceTypeId: 2,
CulpritTypeId: 337,
DmgCaseTypeId: 175,
DmgHistoryStatus: 5214,
PlaqueKindId: 8,
PlaqueSampleId: 10,
DriverIsOwner: 0,
FaultPercent: 100,
ClaimFileTypeId: 23,
},
},
@@ -101,29 +119,35 @@ const FANAVARAN_CLIENT_PROFILES: Record<
location: "210050",
},
defaults: {
AccidentCityId: 701,
AccidentReportTypeId: 155,
AccidentVehicleUsedId: 1,
...SHARED_FANAVARAN_DEFAULTS,
ClaimExpertId: 154,
ExpertiseClaimExpertId: 29,
CompensationReferenceId: 167,
CulpritLicenceTypeId: 2,
CulpritTypeId: 337,
DmgCaseTypeId: 175,
DmgHistoryStatus: 5214,
PlaqueKindId: 8,
PlaqueSampleId: 10,
DriverIsOwner: 0,
FaultPercent: 100,
ClaimFileTypeId: 70,
},
},
moallem: {
key: "moallem",
auth: {
appName: "ItTalie",
secret: "itT@l!3@api",
username: "itTalieUser",
password: "itT@l!3@user",
corpId: "5650",
contractId: "304",
location: "30900",
},
// ClaimExpertId / ClaimFileTypeId not yet confirmed for Moallem — start from
// shared Fanavaran codebook defaults and override after lookup.
defaults: {
...SHARED_FANAVARAN_DEFAULTS,
},
},
};
/** Resolve active Fanavaran tenant from env (`FANAVARAN_CLIENT`) with optional CLIENT_ID fallback. */
export function resolveFanavaranClientKey(): FanavaranClientKey {
const explicit = process.env.FANAVARAN_CLIENT?.trim().toLowerCase();
if (explicit === "parsian" || explicit === "tejaratno") {
if (explicit && isFanavaranClientKey(explicit)) {
return explicit;
}