forked from Yara724/api
Merge pull request 'Added badane API inquiry' (#93) from s.yahyaee/yara724-api:main into main
Reviewed-on: Yara724/api#93
This commit is contained in:
@@ -1016,15 +1016,15 @@ export class RequestManagementService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const personalInquiry = await this.sandHubService.getPersonalInquiry(
|
// const personalInquiry = await this.sandHubService.getPersonalInquiry(
|
||||||
personalNationalCode,
|
// personalNationalCode,
|
||||||
personalBirthDate,
|
// personalBirthDate,
|
||||||
);
|
// );
|
||||||
this.logger.log(
|
// this.logger.log(
|
||||||
`[SANDHUB] personal inquiry success request=${req._id} nationalCode=${personalNationalCode}: ${JSON.stringify(
|
// `[SANDHUB] personal inquiry success request=${req._id} nationalCode=${personalNationalCode}: ${JSON.stringify(
|
||||||
personalInquiry,
|
// personalInquiry,
|
||||||
)}`,
|
// )}`,
|
||||||
);
|
// );
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
`[SANDHUB] personal inquiry failed request=${req._id} nationalCode=${personalNationalCode}: ${err?.message || err}`,
|
`[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)
|
// 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) {
|
if (req.type === BlameRequestType.CAR_BODY && role === PartyRole.FIRST) {
|
||||||
const carBodyInfo = await this.mockCarBodyInsuranceInquiry(
|
const carBodyInfo = await this.sandHubService.getTejaratCarBodyInquiry({
|
||||||
String(req._id),
|
nationalCodeOfInsurer: body.nationalCodeOfInsurer,
|
||||||
body.plate,
|
plate: body.plate,
|
||||||
body.nationalCodeOfInsurer,
|
});
|
||||||
);
|
|
||||||
(party.insurance as any).carBodyInsurance = carBodyInfo;
|
(party.insurance as any).carBodyInsurance = carBodyInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -355,6 +355,58 @@ export class SandHubService {
|
|||||||
return await this.sandHubDbService.findOneBySandHubId(sandHubId);
|
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) {
|
private async makeSandHubRequest(url: string, payload: any, maxRetries = 3) {
|
||||||
if (!(await this.useLiveSandHubApis())) {
|
if (!(await this.useLiveSandHubApis())) {
|
||||||
this.logger.log(`[MOCK] SandHub POST skipped: ${url}`);
|
this.logger.log(`[MOCK] SandHub POST skipped: ${url}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user