urls dynamic integration

This commit is contained in:
2026-10-18 10:20:49 +03:30
parent 47447d1153
commit e7236884db
6 changed files with 103 additions and 44 deletions
+20 -13
View File
@@ -11,7 +11,10 @@ import { InjectModel } from "@nestjs/mongoose";
import { Model } from "mongoose";
import { firstValueFrom } from "rxjs";
import { isAxiosError } from "axios";
import { type FanavaranClientKey } from "src/core/config/fanavaran-client.config";
import {
getFanavaranLookupBaseUrl,
type FanavaranClientKey,
} from "src/core/config/fanavaran-client.config";
import {
LookupModel,
type LookupDocument,
@@ -184,7 +187,11 @@ export class FanavaranLookupService {
}
try {
const data = await this.fetchFromFanavaran(clientKey, url);
const tenantUrl = url.replace(
FANAVARAN_LOOKUP_BASE_URL,
getFanavaranLookupBaseUrl(clientKey),
);
const data = await this.fetchFromFanavaran(clientKey, tenantUrl);
await this.writeCacheFile(clientKey, cacheFile, data);
return data;
} catch (error) {
@@ -249,7 +256,7 @@ export class FanavaranLookupService {
vin: string,
options?: { contractIdOverride?: string },
): Promise<unknown> {
const url = `${FANAVARAN_LOOKUP_BASE_URL}/car/vehicles/inquiry-by-vin?vin=${encodeURIComponent(vin)}`;
const url = `${getFanavaranLookupBaseUrl(clientKey)}/car/vehicles/inquiry-by-vin?vin=${encodeURIComponent(vin)}`;
return this.fetchFromFanavaran(clientKey, url, options);
}
@@ -260,7 +267,7 @@ export class FanavaranLookupService {
options?: { contractIdOverride?: string },
): Promise<unknown> {
const url =
`${FANAVARAN_LOOKUP_BASE_URL}/common/Policies/inquiry-my-policies` +
`${getFanavaranLookupBaseUrl(clientKey)}/common/Policies/inquiry-my-policies` +
`?InsuranceLineId=${insuranceLineId}` +
`&NationalCode=${encodeURIComponent(nationalCode)}`;
return this.fetchFromFanavaran(clientKey, url, options);
@@ -271,7 +278,7 @@ export class FanavaranLookupService {
policyId: number,
options?: { contractIdOverride?: string },
): Promise<unknown> {
const url = `${FANAVARAN_LOOKUP_BASE_URL}/car/third-party-car-policies/${policyId}`;
const url = `${getFanavaranLookupBaseUrl(clientKey)}/car/third-party-car-policies/${policyId}`;
return this.fetchFromFanavaran(clientKey, url, options);
}
@@ -280,7 +287,7 @@ export class FanavaranLookupService {
policyId: number,
options?: { contractIdOverride?: string },
): Promise<unknown> {
const url = `${FANAVARAN_LOOKUP_BASE_URL}/car/vehicle-hull-policies/${policyId}`;
const url = `${getFanavaranLookupBaseUrl(clientKey)}/car/vehicle-hull-policies/${policyId}`;
return this.fetchFromFanavaran(clientKey, url, options);
}
@@ -290,7 +297,7 @@ export class FanavaranLookupService {
policyId: number,
options?: { contractIdOverride?: string },
): Promise<unknown> {
const url = `${FANAVARAN_LOOKUP_BASE_URL}/car/vehicle-hull-policies/${policyId}/dmg-accessories`;
const url = `${getFanavaranLookupBaseUrl(clientKey)}/car/vehicle-hull-policies/${policyId}/dmg-accessories`;
return this.fetchFromFanavaran(clientKey, url, options);
}
@@ -301,7 +308,7 @@ export class FanavaranLookupService {
options?: { contractIdOverride?: string },
): Promise<unknown> {
const query = versionNo == null ? "" : `?versionno=${versionNo}`;
const url = `${FANAVARAN_LOOKUP_BASE_URL}/car/vehicles/${vehicleId}${query}`;
const url = `${getFanavaranLookupBaseUrl(clientKey)}/car/vehicles/${vehicleId}${query}`;
return this.fetchFromFanavaran(clientKey, url, options);
}
@@ -310,7 +317,7 @@ export class FanavaranLookupService {
customerId: number,
options?: { contractIdOverride?: string },
): Promise<unknown> {
const url = `${FANAVARAN_LOOKUP_BASE_URL}/common/customers/${customerId}`;
const url = `${getFanavaranLookupBaseUrl(clientKey)}/common/customers/${customerId}`;
return this.fetchFromFanavaran(clientKey, url, options);
}
@@ -324,7 +331,7 @@ export class FanavaranLookupService {
},
): Promise<unknown> {
const url =
`${FANAVARAN_LOOKUP_BASE_URL}/common/parties/inquiry-by-unique-identifier` +
`${getFanavaranLookupBaseUrl(clientKey)}/common/parties/inquiry-by-unique-identifier` +
`?NationalCode=${encodeURIComponent(params.nationalCode)}` +
`&BirthYear=${params.birthYear}` +
`&BirthMonth=${params.birthMonth}` +
@@ -336,7 +343,7 @@ export class FanavaranLookupService {
clientKey: FanavaranClientKey,
personId: number,
): Promise<unknown> {
const url = `${FANAVARAN_LOOKUP_BASE_URL}/common/other-people/${personId}`;
const url = `${getFanavaranLookupBaseUrl(clientKey)}/common/other-people/${personId}`;
return this.fetchFromFanavaran(clientKey, url);
}
@@ -344,7 +351,7 @@ export class FanavaranLookupService {
clientKey: FanavaranClientKey,
payload: Record<string, unknown>,
): Promise<unknown> {
const url = `${FANAVARAN_LOOKUP_BASE_URL}/common/other-people`;
const url = `${getFanavaranLookupBaseUrl(clientKey)}/common/other-people`;
return this.postToFanavaran(clientKey, url, payload);
}
@@ -407,7 +414,7 @@ export class FanavaranLookupService {
// Try fetching the full list directly from Fanavaran
let companies: unknown;
const url = `${FANAVARAN_LOOKUP_BASE_URL}/common/code-list/insurance-corp`;
const url = `${getFanavaranLookupBaseUrl(clientKey)}/common/code-list/insurance-corp`;
try {
companies = await this.fetchFromFanavaran(clientKey, url);
} catch (error) {