forked from Yara724/api
Compare commits
2 Commits
3b0db0d250
...
768d6d12fe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
768d6d12fe | ||
|
|
84b752c6cc |
@@ -1016,15 +1016,15 @@ export class RequestManagementService {
|
||||
}
|
||||
|
||||
try {
|
||||
const personalInquiry = await this.sandHubService.getPersonalInquiry(
|
||||
personalNationalCode,
|
||||
personalBirthDate,
|
||||
);
|
||||
this.logger.log(
|
||||
`[SANDHUB] personal inquiry success request=${req._id} nationalCode=${personalNationalCode}: ${JSON.stringify(
|
||||
personalInquiry,
|
||||
)}`,
|
||||
);
|
||||
// const personalInquiry = await this.sandHubService.getPersonalInquiry(
|
||||
// personalNationalCode,
|
||||
// personalBirthDate,
|
||||
// );
|
||||
// this.logger.log(
|
||||
// `[SANDHUB] personal inquiry success request=${req._id} nationalCode=${personalNationalCode}: ${JSON.stringify(
|
||||
// personalInquiry,
|
||||
// )}`,
|
||||
// );
|
||||
} catch (err: any) {
|
||||
this.logger.error(
|
||||
`[SANDHUB] personal inquiry failed request=${req._id} nationalCode=${personalNationalCode}: ${err?.message || err}`,
|
||||
@@ -1120,11 +1120,10 @@ export class RequestManagementService {
|
||||
|
||||
// CAR_BODY: persist mocked car-body insurance in party's insurance (same place as usual inquiry)
|
||||
if (req.type === BlameRequestType.CAR_BODY && role === PartyRole.FIRST) {
|
||||
const carBodyInfo = await this.mockCarBodyInsuranceInquiry(
|
||||
String(req._id),
|
||||
body.plate,
|
||||
body.nationalCodeOfInsurer,
|
||||
);
|
||||
const carBodyInfo = await this.sandHubService.getTejaratCarBodyInquiry({
|
||||
nationalCodeOfInsurer: body.nationalCodeOfInsurer,
|
||||
plate: body.plate,
|
||||
});
|
||||
(party.insurance as any).carBodyInsurance = carBodyInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -355,6 +355,58 @@ export class SandHubService {
|
||||
return await this.sandHubDbService.findOneBySandHubId(sandHubId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tejarat block inquiry for Car Body Insurance (Badane).
|
||||
* Returns both raw API response and mapped old-format response structure.
|
||||
*/
|
||||
async getTejaratCarBodyInquiry(userDetail: SandHubDetailDto): Promise<{
|
||||
raw: any;
|
||||
}> {
|
||||
const baseUrl =
|
||||
process.env.TEJARAT_INQUIRY_BASE_URL ?? "http://82.99.202.245:3027";
|
||||
|
||||
// 1. Build payload following the strict data requirements of the external API
|
||||
const requestPayload = {
|
||||
part1: Number(userDetail.plate.leftDigits),
|
||||
part2: String(userDetail.plate.centerAlphabet),
|
||||
part3: Number(userDetail.plate.centerDigits),
|
||||
part4: Number(userDetail.plate.ir),
|
||||
nationalCode: String(userDetail.nationalCodeOfInsurer),
|
||||
};
|
||||
|
||||
const requestUrl = `${baseUrl}/block-inquiry-tejarat/badane`;
|
||||
const live = await this.useLiveSandHubApis();
|
||||
|
||||
let raw: any;
|
||||
|
||||
if (live) {
|
||||
// 2. Safely obtain a fresh or cached access token using your helper
|
||||
const token = await this.getTejaratAccessToken();
|
||||
|
||||
try {
|
||||
// 3. Make the live call using NestJS HttpService + firstValueFrom pattern
|
||||
const response = await firstValueFrom(
|
||||
this.httpService.post(requestUrl, requestPayload, {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
timeout: 30000,
|
||||
}),
|
||||
);
|
||||
raw = response.data;
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`[TEJARAT BADANE ERROR] Request failed for ${requestUrl}: ${error?.message || error}`,
|
||||
error?.stack,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return { raw };
|
||||
}
|
||||
|
||||
private async makeSandHubRequest(url: string, payload: any, maxRetries = 3) {
|
||||
if (!(await this.useLiveSandHubApis())) {
|
||||
this.logger.log(`[MOCK] SandHub POST skipped: ${url}`);
|
||||
|
||||
Reference in New Issue
Block a user