forked from Yara724/api
Fixed personal inquiry
This commit is contained in:
@@ -13,6 +13,7 @@ import axios from "axios";
|
||||
import { SandHubDbService } from "src/sand-hub/entity/db-service/sand-hub.db.service";
|
||||
import { SandHubModel } from "src/sand-hub/entity/schema/sand-hub.schema";
|
||||
import { SandHubDetailDto } from "./dto/sand-hub.dto";
|
||||
import { jalaliToGregorianDate } from "src/helpers/date-jalali";
|
||||
|
||||
@Injectable()
|
||||
export class SandHubService {
|
||||
@@ -473,13 +474,29 @@ export class SandHubService {
|
||||
}
|
||||
}
|
||||
|
||||
async getPersonalInquiry(nationalCode: string, birthDate: number) {
|
||||
/**
|
||||
* Personal identity check against the Tejarat hub. The upstream gateway only
|
||||
* accepts a Gregorian birthdate in `YYYY-MM-DD` form, but every caller in
|
||||
* this codebase has the value as a Jalali date (number `13770624` or string
|
||||
* `"1377-06-24"`/`"1377/06/24"`). We convert here so callers don't have to.
|
||||
*/
|
||||
async getPersonalInquiry(
|
||||
nationalCode: string,
|
||||
birthDate: number | string,
|
||||
) {
|
||||
try {
|
||||
const requestUrl = `${process.env.SANDHUB_BASE_URL}/personal-inquiry/asia`;
|
||||
const requestUrl = `${process.env.SANDHUB_BASE_URL}/personal-inquiry/tejarat-no`;
|
||||
|
||||
const gregorianBirthdate = jalaliToGregorianDate(birthDate);
|
||||
if (!gregorianBirthdate) {
|
||||
throw new BadRequestException(
|
||||
`Invalid birth date for personal inquiry: ${birthDate}. Expected a Jalali date (e.g. 13770624 or "1377-06-24").`,
|
||||
);
|
||||
}
|
||||
|
||||
const requestPayload = {
|
||||
nin: nationalCode,
|
||||
birthDate: birthDate,
|
||||
persianBirthDate: "",
|
||||
nationalCode,
|
||||
birthdate: gregorianBirthdate,
|
||||
};
|
||||
|
||||
const response = await this.makeSandHubRequest(
|
||||
@@ -494,6 +511,12 @@ export class SandHubService {
|
||||
}
|
||||
return response.data;
|
||||
} catch (err) {
|
||||
if (
|
||||
err instanceof BadRequestException ||
|
||||
err instanceof NotFoundException
|
||||
) {
|
||||
throw err;
|
||||
}
|
||||
throw new Error(`Error in finding personal inquiry: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user