forked from Yara724/api
Implemented CAR_BODY fanavaran inquiry
This commit is contained in:
@@ -16,10 +16,17 @@ import { PlateNormalizerService } from "src/utils/plate-normalizer/plate-normali
|
||||
import type { ExternalInquiryType } from "src/common/types/external-inquiry.types";
|
||||
import type { MockInquiryCompanyContext } from "src/common/types/external-inquiry.types";
|
||||
import { OfflineInquiryService } from "src/offline-inquiry/offline-inquiry.service";
|
||||
import { LookupsService } from "src/lookups/lookups.service";
|
||||
import { resolveFanavaranClientKey } from "src/core/config/fanavaran-client.config";
|
||||
import { SandHubDetailDto, SandHubInquiryOptions } from "./dto/sand-hub.dto";
|
||||
import { jalaliToGregorianDate } from "src/helpers/date-jalali";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
import { mapEsgCarBodyPolicyToInquiry } from "./esg-car-body-inquiry.mapper";
|
||||
import type { Plates } from "src/Types&Enums/plate.interface";
|
||||
|
||||
type CarBodyInquiryDetail = Omit<SandHubDetailDto, "plate"> & {
|
||||
plate: Plates | string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class SandHubService {
|
||||
@@ -44,6 +51,7 @@ export class SandHubService {
|
||||
private readonly externalInquirySettings: ExternalInquirySettingsService,
|
||||
private readonly plateNormalizer: PlateNormalizerService,
|
||||
private readonly offlineInquiryService: OfflineInquiryService,
|
||||
private readonly lookupsService: LookupsService,
|
||||
) {}
|
||||
|
||||
private clientRefFrom(options?: SandHubInquiryOptions): string | undefined {
|
||||
@@ -833,6 +841,81 @@ export class SandHubService {
|
||||
return await this.sandHubDbService.findOneBySandHubId(sandHubId);
|
||||
}
|
||||
|
||||
/**
|
||||
* CAR_BODY is the only ESG product that uses the processed Fanavaran lookup.
|
||||
* THIRD_PARTY remains on its established provider-specific inquiry path.
|
||||
*/
|
||||
async getCarBodyInquiry(
|
||||
userDetail: CarBodyInquiryDetail,
|
||||
options?: SandHubInquiryOptions,
|
||||
): Promise<{
|
||||
source:
|
||||
| "ESG_CAR_BODY_INQUIRY"
|
||||
| "ESG_CAR_BODY_VIN_INQUIRY"
|
||||
| "TEJARAT_CAR_BODY_INQUIRY"
|
||||
| "TEJARAT_CAR_BODY_VIN_INQUIRY";
|
||||
raw: any;
|
||||
mapped: Record<string, unknown>;
|
||||
}> {
|
||||
if (!this.shouldUseEsgInquiryProvider()) {
|
||||
const result = await this.getTejaratCarBodyInquiry(
|
||||
userDetail as SandHubDetailDto,
|
||||
options,
|
||||
);
|
||||
return {
|
||||
source:
|
||||
typeof userDetail.plate === "string"
|
||||
? "TEJARAT_CAR_BODY_VIN_INQUIRY"
|
||||
: "TEJARAT_CAR_BODY_INQUIRY",
|
||||
...result,
|
||||
};
|
||||
}
|
||||
|
||||
const live = await this.isInquiryLive("carBodyPlate", options);
|
||||
if (!live) {
|
||||
// Reuse the established local mock contract without sending an HTTP request.
|
||||
const result = await this.getTejaratCarBodyInquiry(
|
||||
userDetail as SandHubDetailDto,
|
||||
options,
|
||||
);
|
||||
return {
|
||||
source:
|
||||
typeof userDetail.plate === "string"
|
||||
? "ESG_CAR_BODY_VIN_INQUIRY"
|
||||
: "ESG_CAR_BODY_INQUIRY",
|
||||
...result,
|
||||
};
|
||||
}
|
||||
|
||||
const plateOrVin = userDetail.plate;
|
||||
const query =
|
||||
typeof plateOrVin === "string"
|
||||
? {
|
||||
nationalCode: String(userDetail.nationalCodeOfInsurer),
|
||||
vin: plateOrVin,
|
||||
}
|
||||
: {
|
||||
nationalCode: String(userDetail.nationalCodeOfInsurer),
|
||||
plaqueLeft: String(plateOrVin.leftDigits),
|
||||
plaqueLetter: String(plateOrVin.centerAlphabet),
|
||||
plaqueRight: String(plateOrVin.centerDigits),
|
||||
plaqueSerial: String(plateOrVin.ir),
|
||||
};
|
||||
const raw = await this.lookupsService.findLastProcessedCarPolicy(
|
||||
"car-body",
|
||||
query,
|
||||
);
|
||||
|
||||
return {
|
||||
source:
|
||||
typeof plateOrVin === "string"
|
||||
? "ESG_CAR_BODY_VIN_INQUIRY"
|
||||
: "ESG_CAR_BODY_INQUIRY",
|
||||
raw,
|
||||
mapped: mapEsgCarBodyPolicyToInquiry(raw),
|
||||
};
|
||||
}
|
||||
|
||||
async getTejaratCarBodyInquiry(
|
||||
userDetail: SandHubDetailDto,
|
||||
options?: SandHubInquiryOptions,
|
||||
|
||||
Reference in New Issue
Block a user