forked from Yara724/api
Route inquiries by participant role
This commit is contained in:
@@ -250,11 +250,16 @@ export class SandHubService {
|
||||
}
|
||||
|
||||
private buildMockCarBodyInquiryRaw(
|
||||
userDetail: SandHubDetailDto,
|
||||
userDetail: CarBodyInquiryDetail,
|
||||
ctx: MockInquiryCompanyContext,
|
||||
): Record<string, unknown> {
|
||||
const companyId = Number(ctx.companyId);
|
||||
const plate = userDetail?.plate;
|
||||
const plate =
|
||||
typeof userDetail?.plate === "string" ? undefined : userDetail?.plate;
|
||||
const vin =
|
||||
typeof userDetail?.plate === "string"
|
||||
? userDetail.plate
|
||||
: "LFP8C7PC3R1K12157";
|
||||
const platePartOne = Number(plate?.leftDigits ?? 16);
|
||||
const platePartThree = Number(plate?.centerDigits ?? 498);
|
||||
const plateSerialNumber = Number(plate?.ir ?? 60);
|
||||
@@ -272,8 +277,8 @@ export class SandHubService {
|
||||
issueDate: "1405/01/16",
|
||||
hasEndorsement: null,
|
||||
motorNumber: "TZ196XYAP223A210074",
|
||||
chassisNumber: "LFP8C7PC3R1K12157",
|
||||
vin: "LFP8C7PC3R1K12157",
|
||||
chassisNumber: vin,
|
||||
vin,
|
||||
plateTypeId: 9,
|
||||
plateTypeTitle: "پلاک قدیمی",
|
||||
platePartOne,
|
||||
@@ -933,28 +938,48 @@ export class SandHubService {
|
||||
}> {
|
||||
const useParsianCarBodyLookup = this.shouldUseParsianCarBodyLookup();
|
||||
const live = await this.isInquiryLive("carBodyPlate", options);
|
||||
const plateOrVin = userDetail.plate;
|
||||
const isVinInquiry = typeof plateOrVin === "string";
|
||||
|
||||
if (!live) {
|
||||
// Mock results are generated for the active deployment. They must not be
|
||||
// treated as evidence of a real insurer and therefore do not go through
|
||||
// the live-policy insurer gate.
|
||||
const result = await this.getTejaratCarBodyInquiry(
|
||||
userDetail as SandHubDetailDto,
|
||||
options,
|
||||
);
|
||||
const ctx = await this.mockCompanyContext(options);
|
||||
const raw = this.buildMockCarBodyInquiryRaw(userDetail, ctx);
|
||||
const result = { raw, mapped: this.mapCarBodyInquiryResponse(raw) };
|
||||
return {
|
||||
source:
|
||||
typeof userDetail.plate === "string"
|
||||
? useParsianCarBodyLookup
|
||||
? "ESG_CAR_BODY_VIN_INQUIRY"
|
||||
: "TEJARAT_CAR_BODY_VIN_INQUIRY"
|
||||
: useParsianCarBodyLookup
|
||||
? "ESG_CAR_BODY_INQUIRY"
|
||||
: "TEJARAT_CAR_BODY_INQUIRY",
|
||||
source: isVinInquiry
|
||||
? useParsianCarBodyLookup
|
||||
? "ESG_CAR_BODY_VIN_INQUIRY"
|
||||
: "TEJARAT_CAR_BODY_VIN_INQUIRY"
|
||||
: useParsianCarBodyLookup
|
||||
? "ESG_CAR_BODY_INQUIRY"
|
||||
: "TEJARAT_CAR_BODY_INQUIRY",
|
||||
...result,
|
||||
};
|
||||
}
|
||||
|
||||
if (isVinInquiry) {
|
||||
const raw = await this.lookupsService.findLastProcessedCarPolicy(
|
||||
"car-body",
|
||||
{
|
||||
nationalCode: String(userDetail.nationalCodeOfInsurer),
|
||||
vin: plateOrVin,
|
||||
},
|
||||
);
|
||||
if (useParsianCarBodyLookup) {
|
||||
this.assertParsianCarBodyLookupMatchesDeployment();
|
||||
}
|
||||
return {
|
||||
source: useParsianCarBodyLookup
|
||||
? "ESG_CAR_BODY_VIN_INQUIRY"
|
||||
: "TEJARAT_CAR_BODY_VIN_INQUIRY",
|
||||
raw,
|
||||
mapped: mapEsgCarBodyPolicyToInquiry(raw),
|
||||
};
|
||||
}
|
||||
|
||||
if (!useParsianCarBodyLookup) {
|
||||
const result = await this.getTejaratCarBodyInquiry(
|
||||
userDetail as SandHubDetailDto,
|
||||
@@ -962,28 +987,18 @@ export class SandHubService {
|
||||
);
|
||||
this.assertInsuranceMatchesDeployment(result.mapped, "CAR_BODY");
|
||||
return {
|
||||
source:
|
||||
typeof userDetail.plate === "string"
|
||||
? "TEJARAT_CAR_BODY_VIN_INQUIRY"
|
||||
: "TEJARAT_CAR_BODY_INQUIRY",
|
||||
source: "TEJARAT_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 query = {
|
||||
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,
|
||||
@@ -991,10 +1006,7 @@ export class SandHubService {
|
||||
this.assertParsianCarBodyLookupMatchesDeployment();
|
||||
|
||||
return {
|
||||
source:
|
||||
typeof plateOrVin === "string"
|
||||
? "ESG_CAR_BODY_VIN_INQUIRY"
|
||||
: "ESG_CAR_BODY_INQUIRY",
|
||||
source: "ESG_CAR_BODY_INQUIRY",
|
||||
raw,
|
||||
mapped: mapEsgCarBodyPolicyToInquiry(raw),
|
||||
};
|
||||
@@ -1109,16 +1121,19 @@ export class SandHubService {
|
||||
* `buildMockPlateInquiryRaw` so the downstream mapper (`mapEsgPolicyByPlateToOldFormat`)
|
||||
* can normalise it into the same `{ raw, mapped }` contract used by the plate path.
|
||||
*
|
||||
* @param chassisNo - 17-character VIN / chassis number
|
||||
* @param identity - policyholder national code and 17-character VIN/chassis
|
||||
* @param options - optional per-tenant client scope
|
||||
*/
|
||||
async getPolicyByChassisInquiry(
|
||||
chassisNo: string,
|
||||
identity: { nationalCode: string; chassis: string },
|
||||
options?: SandHubInquiryOptions,
|
||||
): Promise<{ raw: any; mapped: any }> {
|
||||
const baseUrl = process.env.ESG_URL ?? "http://192.168.20.22:8085";
|
||||
const requestUrl = `${baseUrl}/inquiry/policyByChassis`;
|
||||
const requestPayload = { chassisNo };
|
||||
const requestPayload = {
|
||||
nationalCode: String(identity.nationalCode),
|
||||
chassis: String(identity.chassis),
|
||||
};
|
||||
|
||||
const live = await this.isInquiryLive("vinChassis", options);
|
||||
|
||||
@@ -1126,7 +1141,7 @@ export class SandHubService {
|
||||
const ctx = await this.mockCompanyContext(options);
|
||||
const raw = this.buildMockPlateInquiryRaw(ctx);
|
||||
this.logger.debug(
|
||||
`[MOCK] getPolicyByChassisInquiry chassisNo=${chassisNo}`,
|
||||
`[MOCK] getPolicyByChassisInquiry nationalCode=${identity.nationalCode} chassis=${identity.chassis}`,
|
||||
);
|
||||
const mapped = this.mapEsgPolicyByPlateToOldFormat(raw);
|
||||
this.enforceDeploymentClientMatch(mapped, "THIRD_PARTY", options);
|
||||
|
||||
Reference in New Issue
Block a user