forked from Yara724/api
Merge pull request 'Fixed correct clientId gets replaced in CAR_BODY' (#113) from s.yahyaee/yara724-api:main into main
Reviewed-on: Yara724/api#113
This commit is contained in:
@@ -1248,9 +1248,9 @@ export class RequestManagementService {
|
||||
);
|
||||
}
|
||||
|
||||
// Raw + mapped stored under vehicle (same pattern as third-party inquiry)
|
||||
// Raw + mapped stored under vehicle
|
||||
party.vehicle.inquiry = {
|
||||
...party.vehicle.inquiry, // preserve existing third-party inquiry if present
|
||||
...party.vehicle.inquiry,
|
||||
carBody: {
|
||||
source: "TEJARAT_CAR_BODY_INQUIRY",
|
||||
raw: carBodyInfo.raw,
|
||||
@@ -1258,7 +1258,7 @@ export class RequestManagementService {
|
||||
},
|
||||
};
|
||||
|
||||
// Flat key fields extracted alongside third-party insurance fields
|
||||
// Flat insurance fields from car body inquiry
|
||||
const m = carBodyInfo.mapped;
|
||||
(party.insurance as any).carBodyInsurance = {
|
||||
policyNumber: m.policyNumber ?? null,
|
||||
@@ -1279,6 +1279,45 @@ export class RequestManagementService {
|
||||
lossDocuments: m.lossDocuments ?? [],
|
||||
hasEndorsement: m.hasEndorsement ?? null,
|
||||
};
|
||||
|
||||
// ← THE FIX: overwrite clientId with car-body insurer's clientId
|
||||
// For CAR_BODY files the relevant insurer is the one covering the car body,
|
||||
// not the third-party liability insurer resolved earlier in this function.
|
||||
const carBodyCompanyCode = m.companyId ?? m.CompanyCode;
|
||||
const carBodyCompanyName = m.CompanyName ?? m.companyPersianName;
|
||||
|
||||
if (carBodyCompanyCode) {
|
||||
let carBodyClient: any =
|
||||
await this.clientService.findClientWithCompanyCode(
|
||||
Number(carBodyCompanyCode),
|
||||
);
|
||||
|
||||
if (!carBodyClient && carBodyCompanyName) {
|
||||
await this.clientService.addClient({
|
||||
clientName: {
|
||||
persian: carBodyCompanyName,
|
||||
english: null,
|
||||
},
|
||||
clientCode: Number(carBodyCompanyCode),
|
||||
useExpertMode: "legal",
|
||||
});
|
||||
// Re-fetch after creation so we get the actual document with _id
|
||||
carBodyClient = await this.clientService.findClientWithCompanyCode(
|
||||
Number(carBodyCompanyCode),
|
||||
);
|
||||
}
|
||||
|
||||
const carBodyClientId =
|
||||
(carBodyClient as any)?._id ?? (carBodyClient as any)?._doc?._id;
|
||||
|
||||
if (carBodyClientId) {
|
||||
// Overwrite the third-party clientId set earlier in this function
|
||||
party.person.clientId = carBodyClientId;
|
||||
this.logger.log(
|
||||
`[CAR_BODY] Overriding party clientId with car-body insurer clientId=${carBodyClientId} companyCode=${carBodyCompanyCode} for request=${req._id}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Advance workflow
|
||||
|
||||
Reference in New Issue
Block a user