update the lookups list

This commit is contained in:
2026-09-07 15:08:08 +03:30
parent 80e112f09b
commit c7cd9e8ce5
11 changed files with 1161 additions and 72 deletions

View File

@@ -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,
@@ -176,9 +180,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(
@@ -500,11 +576,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> {