Added roles for GET car parts APIs

This commit is contained in:
2026-07-02 13:17:04 +03:30
parent b43f1a86dc
commit 9e2cf9bcdf
2 changed files with 98 additions and 33 deletions

View File

@@ -1165,7 +1165,9 @@ export class RequestManagementService {
{},
err,
);
await (req as any).save();
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
$set: { inquiries: req.inquiries },
});
throw new HttpException("Inquiry failed", HttpStatus.BAD_REQUEST);
}
@@ -1180,7 +1182,9 @@ export class RequestManagementService {
raw: inquiryRaw,
mapped: inquiryMapped,
});
await (req as any).save();
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
$set: { inquiries: req.inquiries },
});
throw new HttpException(
inquiryMapped.Error.Message || "Inquiry returned error",
HttpStatus.BAD_REQUEST,
@@ -1232,7 +1236,9 @@ export class RequestManagementService {
`[SANDHUB] personal inquiry failed request=${req._id} nationalCode=${personalNationalCode}: ${err?.message || err}`,
);
this.recordPartyCaseInquiryStatus(req, "person", role, false, {}, err);
await (req as any).save();
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
$set: { inquiries: req.inquiries },
});
throw new HttpException(
"Personal identity inquiry failed",
HttpStatus.BAD_REQUEST,
@@ -1353,7 +1359,9 @@ export class RequestManagementService {
{},
err,
);
await (req as any).save();
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
$set: { inquiries: req.inquiries },
});
throw new HttpException(
"Car body inquiry failed",
HttpStatus.BAD_REQUEST,
@@ -1422,8 +1430,7 @@ export class RequestManagementService {
await this.advanceWorkflowToNext(req, stepKey);
// History
if (!Array.isArray(req.history)) req.history = [];
req.history.push({
const historyEntry: any = {
type: `${stepKey}_SUBMITTED`,
actor: {
actorId: Types.ObjectId.isValid(user?.sub)
@@ -1437,9 +1444,24 @@ export class RequestManagementService {
companyCode,
companyName: clientName,
},
} as any);
};
await (req as any).save();
// Use findByIdAndUpdate instead of save() to avoid Mongoose VersionError
// when two parties submit their forms concurrently. Each party only writes
// its own paths, so the $set operations are non-overlapping and safe.
await this.blameRequestDbService.findByIdAndUpdate(req._id, {
$set: {
[`parties.${idx}.person`]: party.person,
[`parties.${idx}.vehicle`]: party.vehicle,
[`parties.${idx}.insurance`]: party.insurance,
inquiries: req.inquiries,
"workflow.completedSteps": req.workflow.completedSteps,
"workflow.currentStep": req.workflow.currentStep,
"workflow.nextStep": req.workflow.nextStep,
status: req.status,
},
$push: { history: historyEntry },
});
return {
requestId: req._id,