Fixed images being removed, fixed v4/v5 wrong status on uploadDocument

This commit is contained in:
SepehrYahyaee
2026-09-16 12:50:12 +03:30
parent dc30518a7f
commit fee0bcb5be
4 changed files with 305 additions and 12 deletions

View File

@@ -6452,14 +6452,22 @@ export class ClaimRequestManagementService {
);
}
// Schedule retry for attachments
await this.scheduleFanavaranRetry(
claimCaseId,
"attachments",
() => this.autoSubmitFanavaranAttachment(claimCaseId, file, options),
logPrefix,
{ error, clientKey },
);
// Schedule retry for attachments — never let retry bookkeeping fail the
// caller: local media/docs are already persisted before this submit.
try {
await this.scheduleFanavaranRetry(
claimCaseId,
"attachments",
() => this.autoSubmitFanavaranAttachment(claimCaseId, file, options),
logPrefix,
{ error, clientKey },
);
} catch (retryScheduleError) {
this.logger.error(
`${logPrefix} Failed to schedule Fanavaran attachment retry`,
retryScheduleError,
);
}
return {
attempted: true,
@@ -10911,7 +10919,14 @@ export class ClaimRequestManagementService {
...nextMedia[idx],
...captureData,
};
updateData["media.damagedParts"] = nextMedia;
// Per-index $set avoids lost updates when clients upload multiple parts
// in parallel (whole-array replace raced with Fanavaran-awaited requests).
// Legacy object maps still need a full write to migrate to array shape.
if (!Array.isArray(claimCase.media?.damagedParts)) {
updateData["media.damagedParts"] = nextMedia;
} else {
updateData[`media.damagedParts.${idx}`] = nextMedia[idx];
}
if (
isResendCapture &&
nextSelected.length !== selectedBeforeNorm.length
@@ -10920,10 +10935,14 @@ export class ClaimRequestManagementService {
}
}
const updatedClaim = await this.claimCaseDbService.findByIdAndUpdate(
await this.claimCaseDbService.findByIdAndUpdate(
claimRequestId,
updateData,
);
// Re-read so capture-progress sees sibling concurrent part/angle writes.
const updatedClaim =
(await this.claimCaseDbService.findById(claimRequestId)) ??
claimCase;
if (isResendCapture) {
await this.tryFinalizeExpertResendAfterUserAction(