forked from Yara724/api
Fixed vin inquiry
This commit is contained in:
@@ -1842,8 +1842,14 @@ export class RequestManagementService {
|
|||||||
|
|
||||||
if (!party.vehicle) party.vehicle = {} as any;
|
if (!party.vehicle) party.vehicle = {} as any;
|
||||||
party.vehicle.isNew = body.isNewCar;
|
party.vehicle.isNew = body.isNewCar;
|
||||||
// Store VIN in vehicle.vin; leave plateId empty for VIN-based inquiries
|
// Derive plateId from the plate parts returned by the VIN inquiry (plk → Plk1/Plk2/Plk3/PlkSrl).
|
||||||
party.vehicle.vin = body.vin;
|
// Falls back to the submitted VIN so plateId is never empty.
|
||||||
|
party.vehicle.plateId = this.plateToPlateIdString({
|
||||||
|
ir: inquiryMapped?.PlkSrl,
|
||||||
|
leftDigits: inquiryMapped?.Plk1,
|
||||||
|
centerAlphabet: inquiryMapped?.Plk2 ?? inquiryMapped?.plateLetterid,
|
||||||
|
centerDigits: inquiryMapped?.Plk3,
|
||||||
|
}) || body.vin;
|
||||||
party.vehicle.name = inquiryMapped?.MapTypNam;
|
party.vehicle.name = inquiryMapped?.MapTypNam;
|
||||||
party.vehicle.type = `${inquiryMapped?.UsageField} / ${inquiryMapped?.MapUsageName || "-"}`;
|
party.vehicle.type = `${inquiryMapped?.UsageField} / ${inquiryMapped?.MapUsageName || "-"}`;
|
||||||
party.vehicle.inquiry = {
|
party.vehicle.inquiry = {
|
||||||
@@ -9508,8 +9514,14 @@ export class RequestManagementService {
|
|||||||
(party.person as any).licenseType = (partyData as any).licenseType;
|
(party.person as any).licenseType = (partyData as any).licenseType;
|
||||||
|
|
||||||
if (!party.vehicle) party.vehicle = {} as any;
|
if (!party.vehicle) party.vehicle = {} as any;
|
||||||
// Store VIN in vehicle.vin; leave plateId empty for VIN-based inquiries
|
// Derive plateId from the plate parts returned by the VIN inquiry (plk → Plk1/Plk2/Plk3/PlkSrl).
|
||||||
party.vehicle.vin = partyData.vin;
|
// Falls back to the submitted VIN so plateId is never empty.
|
||||||
|
party.vehicle.plateId = this.plateToPlateIdString({
|
||||||
|
ir: inquiryMapped?.PlkSrl,
|
||||||
|
leftDigits: inquiryMapped?.Plk1,
|
||||||
|
centerAlphabet: inquiryMapped?.Plk2 ?? inquiryMapped?.plateLetterid,
|
||||||
|
centerDigits: inquiryMapped?.Plk3,
|
||||||
|
}) || partyData.vin;
|
||||||
party.vehicle.name = inquiryMapped?.MapTypNam;
|
party.vehicle.name = inquiryMapped?.MapTypNam;
|
||||||
party.vehicle.type = `${inquiryMapped?.UsageField ?? ""} / ${inquiryMapped?.UsageName ?? inquiryMapped?.MapUsageName ?? "-"}`;
|
party.vehicle.type = `${inquiryMapped?.UsageField ?? ""} / ${inquiryMapped?.UsageName ?? inquiryMapped?.MapUsageName ?? "-"}`;
|
||||||
party.vehicle.inquiry = {
|
party.vehicle.inquiry = {
|
||||||
|
|||||||
@@ -1027,12 +1027,59 @@ export class SandHubService {
|
|||||||
/**
|
/**
|
||||||
* Maps the new SandHub API response format to the old format expected by the application
|
* Maps the new SandHub API response format to the old format expected by the application
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* Parse the `plk` string returned by the ESG VIN inquiry into the four
|
||||||
|
* numeric/text plate parts used everywhere in the system.
|
||||||
|
*
|
||||||
|
* ESG format example: `"782د29 60"`
|
||||||
|
* → Plk3=782 (center digits) Plk2="د" (center letter)
|
||||||
|
* Plk1=29 (left digits) PlkSrl=60 (IR region code)
|
||||||
|
*
|
||||||
|
* Returns null if the string does not match the expected pattern.
|
||||||
|
*/
|
||||||
|
private parsePlkString(
|
||||||
|
plk: string,
|
||||||
|
): { Plk1: number; Plk2: string; Plk3: number; PlkSrl: number } | null {
|
||||||
|
if (!plk || typeof plk !== "string") return null;
|
||||||
|
// Pattern: {centerDigits}{centerLetter(s)}{leftDigits}<space>{ir}
|
||||||
|
const m = plk.trim().match(/^(\d+)([^\d\s]+)(\d+)\s+(\d+)$/);
|
||||||
|
if (!m) return null;
|
||||||
|
const Plk3 = parseInt(m[1], 10); // center digits
|
||||||
|
const Plk2 = this.plateNormalizer.normalizePlateText(m[2]);
|
||||||
|
const Plk1 = parseInt(m[3], 10); // left digits
|
||||||
|
const PlkSrl = parseInt(m[4], 10); // IR region code
|
||||||
|
if (!Number.isFinite(Plk3) || !Number.isFinite(Plk1) || !Number.isFinite(PlkSrl) || !Plk2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return { Plk1, Plk2, Plk3, PlkSrl };
|
||||||
|
}
|
||||||
|
|
||||||
private mapNewApiResponseToOldFormat(newResponse: any): any {
|
private mapNewApiResponseToOldFormat(newResponse: any): any {
|
||||||
if (!newResponse) return newResponse;
|
if (!newResponse) return newResponse;
|
||||||
|
|
||||||
|
// If the response carries a `plk` plate string (VIN inquiry) but lacks the
|
||||||
|
// individual Plk1/Plk2/Plk3/PlkSrl fields, parse and inject them so that
|
||||||
|
// all downstream plate-handling code works identically to the plate flow.
|
||||||
|
let plkParts: { Plk1: number; Plk2: string; Plk3: number; PlkSrl: number } | null = null;
|
||||||
|
if (
|
||||||
|
newResponse.plk &&
|
||||||
|
newResponse.Plk1 == null &&
|
||||||
|
newResponse.Plk3 == null &&
|
||||||
|
newResponse.PlkSrl == null
|
||||||
|
) {
|
||||||
|
plkParts = this.parsePlkString(String(newResponse.plk));
|
||||||
|
}
|
||||||
|
|
||||||
// Map the new field names to the old field names
|
// Map the new field names to the old field names
|
||||||
return {
|
return {
|
||||||
...newResponse,
|
...newResponse,
|
||||||
|
...(plkParts ? {
|
||||||
|
Plk1: plkParts.Plk1,
|
||||||
|
Plk2: plkParts.Plk2,
|
||||||
|
Plk3: plkParts.Plk3,
|
||||||
|
PlkSrl: plkParts.PlkSrl,
|
||||||
|
plateLetterid: plkParts.Plk2,
|
||||||
|
} : {}),
|
||||||
// Company information
|
// Company information
|
||||||
CompanyCode: newResponse.companyId || newResponse.CompanyCode,
|
CompanyCode: newResponse.companyId || newResponse.CompanyCode,
|
||||||
CompanyName: newResponse.companyPersianName || newResponse.CompanyName,
|
CompanyName: newResponse.companyPersianName || newResponse.CompanyName,
|
||||||
|
|||||||
Reference in New Issue
Block a user