forked from Yara724/api
update the car name
This commit is contained in:
@@ -356,15 +356,16 @@ export class InquiryRefreshService {
|
||||
...(existingCarBody ? { carBody: existingCarBody } : {}),
|
||||
};
|
||||
|
||||
next.vehicle.name =
|
||||
mapped.vehiclePersianName ||
|
||||
mapped.MapTypNam ||
|
||||
next.vehicle.name ||
|
||||
"اطلاعات این گزینه در استعلام موجود نیست";
|
||||
next.vehicle.type =
|
||||
mapped.persianCarType ||
|
||||
mapped.MapUsageName ||
|
||||
next.vehicle.type;
|
||||
const vehicleName = this.resolveVehicleName(mapped, raw);
|
||||
if (vehicleName) {
|
||||
next.vehicle.name = vehicleName;
|
||||
}
|
||||
|
||||
const vehicleType = this.resolveVehicleType(mapped, raw);
|
||||
if (vehicleType) {
|
||||
next.vehicle.type = vehicleType;
|
||||
}
|
||||
|
||||
next.insurance.policyNumber =
|
||||
mapped.LastCompanyDocumentNumber ||
|
||||
mapped.insuranceNumber ||
|
||||
@@ -387,6 +388,54 @@ export class InquiryRefreshService {
|
||||
return next;
|
||||
}
|
||||
|
||||
/** Same sources as FIRST_INITIAL_FORM + common Tejarat/ESG field aliases */
|
||||
private resolveVehicleName(
|
||||
mapped: Record<string, any>,
|
||||
raw: Record<string, any>,
|
||||
): string | undefined {
|
||||
return this.firstNonEmptyString(
|
||||
mapped?.vehiclePersianName,
|
||||
mapped?.MapTypNam,
|
||||
mapped?.TypeNameCii,
|
||||
mapped?.CarName,
|
||||
raw?.vehiclePersianName,
|
||||
raw?.MapTypNam,
|
||||
raw?.TypeNameCii,
|
||||
raw?.CarName,
|
||||
);
|
||||
}
|
||||
|
||||
/** Matches request-management: `${UsageField} / ${MapUsageName}` */
|
||||
private resolveVehicleType(
|
||||
mapped: Record<string, any>,
|
||||
raw: Record<string, any>,
|
||||
): string | undefined {
|
||||
const usageField = this.firstNonEmptyString(
|
||||
mapped?.UsageField,
|
||||
mapped?.persianCarType,
|
||||
raw?.UsageField,
|
||||
raw?.UsageNameCii,
|
||||
);
|
||||
const usageName = this.firstNonEmptyString(
|
||||
mapped?.MapUsageName,
|
||||
raw?.MapUsageName,
|
||||
);
|
||||
|
||||
if (usageField && usageName) {
|
||||
return `${usageField} / ${usageName}`;
|
||||
}
|
||||
return usageField || usageName;
|
||||
}
|
||||
|
||||
private firstNonEmptyString(...values: unknown[]): string | undefined {
|
||||
for (const value of values) {
|
||||
if (value === undefined || value === null) continue;
|
||||
const text = String(value).trim();
|
||||
if (text) return text;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutate an existing Mongoose document in place instead of $set on a lean-cloned
|
||||
* parties array (which causes "Cast to embedded failed" on ObjectId sub-fields).
|
||||
|
||||
Reference in New Issue
Block a user