forked from Yara724/api
Merge pull request 'main' (#144) from s.hajizadeh/yara724api:main into main
Reviewed-on: Yara724/api#144
This commit is contained in:
@@ -137,13 +137,7 @@ export class InquiryRefreshService {
|
|||||||
|
|
||||||
let claimsUpdated = 0;
|
let claimsUpdated = 0;
|
||||||
if (blameChanged && !dryRun) {
|
if (blameChanged && !dryRun) {
|
||||||
await this.blameRequestDbService.findByIdAndUpdate(doc._id, {
|
await this.persistBlameCaseUpdates(doc._id, roles, parties, inquiries);
|
||||||
$set: {
|
|
||||||
parties,
|
|
||||||
inquiries,
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
claimsUpdated = await this.syncInquiriesToClaims(
|
claimsUpdated = await this.syncInquiriesToClaims(
|
||||||
String(doc._id),
|
String(doc._id),
|
||||||
@@ -377,8 +371,14 @@ export class InquiryRefreshService {
|
|||||||
next.insurance.policyNumber;
|
next.insurance.policyNumber;
|
||||||
next.insurance.company =
|
next.insurance.company =
|
||||||
mapped.companyPersianName || mapped.CompanyName || next.insurance.company;
|
mapped.companyPersianName || mapped.CompanyName || next.insurance.company;
|
||||||
|
const financialCeiling =
|
||||||
|
mapped.financeCoverage ??
|
||||||
|
mapped.FinancialCvrCptl ??
|
||||||
|
next.insurance.financialCeiling;
|
||||||
next.insurance.financialCeiling =
|
next.insurance.financialCeiling =
|
||||||
mapped.financeCoverage || mapped.FinancialCvrCptl || next.insurance.financialCeiling;
|
financialCeiling !== undefined && financialCeiling !== null
|
||||||
|
? String(financialCeiling)
|
||||||
|
: next.insurance.financialCeiling;
|
||||||
next.insurance.startDate =
|
next.insurance.startDate =
|
||||||
mapped.persianStartDate || mapped.IssueDate || mapped.SatrtDate || next.insurance.startDate;
|
mapped.persianStartDate || mapped.IssueDate || mapped.SatrtDate || next.insurance.startDate;
|
||||||
next.insurance.endDate =
|
next.insurance.endDate =
|
||||||
@@ -387,6 +387,70 @@ export class InquiryRefreshService {
|
|||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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).
|
||||||
|
*/
|
||||||
|
private async persistBlameCaseUpdates(
|
||||||
|
blameId: string | Types.ObjectId,
|
||||||
|
roles: PartyRole[],
|
||||||
|
updatedParties: Record<string, any>[],
|
||||||
|
inquiries: Record<string, any>,
|
||||||
|
): Promise<void> {
|
||||||
|
const blameDoc = await this.blameRequestDbService.findById(blameId);
|
||||||
|
if (!blameDoc) {
|
||||||
|
throw new NotFoundException(`Blame case ${blameId} not found`);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const role of roles) {
|
||||||
|
const memParty = updatedParties.find((party) => party?.role === role);
|
||||||
|
const docIdx = blameDoc.parties.findIndex((party) => party?.role === role);
|
||||||
|
if (!memParty || docIdx === -1) continue;
|
||||||
|
|
||||||
|
const party = blameDoc.parties[docIdx];
|
||||||
|
if (!party.vehicle) party.vehicle = {} as any;
|
||||||
|
if (!party.insurance) party.insurance = {} as any;
|
||||||
|
|
||||||
|
if (memParty.vehicle?.inquiry) {
|
||||||
|
party.vehicle.inquiry = memParty.vehicle.inquiry;
|
||||||
|
}
|
||||||
|
if (memParty.vehicle?.name !== undefined) {
|
||||||
|
party.vehicle.name = memParty.vehicle.name;
|
||||||
|
}
|
||||||
|
if (memParty.vehicle?.type !== undefined) {
|
||||||
|
party.vehicle.type = memParty.vehicle.type;
|
||||||
|
}
|
||||||
|
if (memParty.vehicle?.plateId !== undefined) {
|
||||||
|
party.vehicle.plateId = memParty.vehicle.plateId;
|
||||||
|
}
|
||||||
|
blameDoc.markModified(`parties.${docIdx}.vehicle`);
|
||||||
|
|
||||||
|
if (memParty.insurance) {
|
||||||
|
if (memParty.insurance.policyNumber !== undefined) {
|
||||||
|
party.insurance.policyNumber = memParty.insurance.policyNumber;
|
||||||
|
}
|
||||||
|
if (memParty.insurance.company !== undefined) {
|
||||||
|
party.insurance.company = memParty.insurance.company;
|
||||||
|
}
|
||||||
|
if (memParty.insurance.financialCeiling !== undefined) {
|
||||||
|
party.insurance.financialCeiling = String(memParty.insurance.financialCeiling);
|
||||||
|
}
|
||||||
|
if (memParty.insurance.startDate !== undefined) {
|
||||||
|
party.insurance.startDate = memParty.insurance.startDate;
|
||||||
|
}
|
||||||
|
if (memParty.insurance.endDate !== undefined) {
|
||||||
|
party.insurance.endDate = memParty.insurance.endDate;
|
||||||
|
}
|
||||||
|
blameDoc.markModified(`parties.${docIdx}.insurance`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
blameDoc.set("inquiries", inquiries);
|
||||||
|
blameDoc.markModified("inquiries");
|
||||||
|
blameDoc.set("updatedAt", new Date());
|
||||||
|
await blameDoc.save();
|
||||||
|
}
|
||||||
|
|
||||||
private async syncInquiriesToClaims(
|
private async syncInquiriesToClaims(
|
||||||
blameRequestId: string,
|
blameRequestId: string,
|
||||||
inquiries: Record<string, any>,
|
inquiries: Record<string, any>,
|
||||||
|
|||||||
Reference in New Issue
Block a user