forked from Yara724/api
Merge pull request 'main' (#296) from s.hajizadeh/yara724api:main into main
Reviewed-on: Yara724/api#296
This commit is contained in:
@@ -14,6 +14,10 @@ import {
|
||||
TEJARAT_STATIC_ACCIDENT_FILES,
|
||||
} from "src/fanavaran/fanavaran-lookup.config";
|
||||
import { FanavaranLookupService } from "src/fanavaran/fanavaran-lookup.service";
|
||||
import {
|
||||
parseJalaliDateParts,
|
||||
selectFanavaranDriverId,
|
||||
} from "src/claim-request-management/fanavaran-driver-inquiry";
|
||||
import { LookupDbService } from "./entities/db-service/lookup.db.service";
|
||||
import {
|
||||
asObjectRecord,
|
||||
@@ -178,9 +182,81 @@ export class LookupsService {
|
||||
return await this.getClientRemoteLookup("dmg-business-line");
|
||||
}
|
||||
|
||||
async inquiryByUniqueIdentifier(query: {
|
||||
nationalCode?: string;
|
||||
birthday?: string;
|
||||
birthYear?: string | number;
|
||||
birthMonth?: string | number;
|
||||
birthDay?: string | number;
|
||||
}): Promise<unknown> {
|
||||
const nationalCode = String(query.nationalCode ?? "").trim();
|
||||
if (!nationalCode) {
|
||||
throw new BadRequestException("nationalCode is required");
|
||||
}
|
||||
|
||||
const fromParts = {
|
||||
year: Number(query.birthYear),
|
||||
month: Number(query.birthMonth),
|
||||
day: Number(query.birthDay),
|
||||
};
|
||||
const parsed =
|
||||
Number.isFinite(fromParts.year) &&
|
||||
fromParts.year > 0 &&
|
||||
Number.isFinite(fromParts.month) &&
|
||||
fromParts.month > 0 &&
|
||||
Number.isFinite(fromParts.day) &&
|
||||
fromParts.day > 0
|
||||
? fromParts
|
||||
: parseJalaliDateParts(query.birthday);
|
||||
|
||||
if (!parsed) {
|
||||
throw new BadRequestException(
|
||||
"birthday (e.g. 13480313) or birthYear+birthMonth+birthDay is required",
|
||||
);
|
||||
}
|
||||
|
||||
const clientKey = this.activeClientKey();
|
||||
const rows = await this.fanavaranLookupService.inquiryByUniqueIdentifier(
|
||||
clientKey,
|
||||
{
|
||||
nationalCode,
|
||||
birthYear: parsed.year,
|
||||
birthMonth: parsed.month,
|
||||
birthDay: parsed.day,
|
||||
},
|
||||
);
|
||||
return {
|
||||
nationalCode,
|
||||
birthday: parsed,
|
||||
driverId: selectFanavaranDriverId(rows, undefined),
|
||||
insurerId: selectFanavaranDriverId(rows, true),
|
||||
parties: rows,
|
||||
};
|
||||
}
|
||||
|
||||
async inquiryByVin(vin: string): Promise<unknown> {
|
||||
const clientKey = this.activeClientKey();
|
||||
return this.fanavaranLookupService.inquiryByVin(clientKey, vin);
|
||||
const raw = await this.fanavaranLookupService.inquiryByVin(clientKey, vin);
|
||||
if (Array.isArray(raw)) {
|
||||
if (raw.length === 0) {
|
||||
throw new NotFoundException(
|
||||
`Fanavaran vehicle for VIN ${vin} was not found.`,
|
||||
);
|
||||
}
|
||||
return Promise.all(
|
||||
raw.map(async (item) => {
|
||||
const vehicle = asObjectRecord(item);
|
||||
return vehicle ? this.enrichVehicle(vehicle) : item;
|
||||
}),
|
||||
);
|
||||
}
|
||||
const vehicle = asObjectRecord(raw);
|
||||
if (!vehicle) {
|
||||
throw new NotFoundException(
|
||||
`Fanavaran vehicle for VIN ${vin} was not found.`,
|
||||
);
|
||||
}
|
||||
return this.enrichVehicle(vehicle);
|
||||
}
|
||||
|
||||
async myPolicies(
|
||||
@@ -514,11 +590,19 @@ export class LookupsService {
|
||||
|
||||
async vehicleById(vehicleId: number, versionNo?: number): Promise<unknown> {
|
||||
const clientKey = this.activeClientKey();
|
||||
return this.fanavaranLookupService.vehicleById(
|
||||
clientKey,
|
||||
vehicleId,
|
||||
versionNo,
|
||||
const vehicle = asObjectRecord(
|
||||
await this.fanavaranLookupService.vehicleById(
|
||||
clientKey,
|
||||
vehicleId,
|
||||
versionNo,
|
||||
),
|
||||
);
|
||||
if (!vehicle) {
|
||||
throw new NotFoundException(
|
||||
`Fanavaran vehicle ${vehicleId} was not found.`,
|
||||
);
|
||||
}
|
||||
return this.enrichVehicle(vehicle);
|
||||
}
|
||||
|
||||
async customerById(customerId: number): Promise<unknown> {
|
||||
|
||||
Reference in New Issue
Block a user