forked from Yara724/api
Fixed bugs
This commit is contained in:
@@ -4880,12 +4880,75 @@ export class ClaimRequestManagementService {
|
||||
let allDocumentsUploaded = false;
|
||||
let remaining = 0;
|
||||
|
||||
// Will be true when this upload also completes capture-phase docs AND
|
||||
// every angle + every selected damaged part has already been captured.
|
||||
// In that case we advance the workflow exactly like `capturePartV2` does
|
||||
// when the user finishes the last capture — otherwise the user would be
|
||||
// stuck in CAPTURE_PART_DAMAGES with all captures done but no more
|
||||
// captures to upload to trigger the transition.
|
||||
let captureStepCompletedOnThisUpload = false;
|
||||
|
||||
if (!isResendUpload) {
|
||||
if (isCapturePhaseDocUpload) {
|
||||
const afterThis = (k: string) =>
|
||||
k === body.documentKey || this.isRequiredDocumentUploadedOnClaim(claimCase, k);
|
||||
remaining = CAPTURE_PHASE_DAMAGED_PARTY_DOC_KEYS.filter((k) => !afterThis(k)).length;
|
||||
allDocumentsUploaded = false;
|
||||
|
||||
if (remaining === 0) {
|
||||
// After this upload all 3 capture-phase docs will be on the claim.
|
||||
// Check angles + parts captures using the in-memory claim media.
|
||||
const carAnglesData = (claimCase.media as any)?.carAngles;
|
||||
const damagedPartsData = (claimCase.media as any)?.damagedParts;
|
||||
const selectedNorm = normalizeDamageSelectedParts(
|
||||
claimCase.damage?.selectedParts,
|
||||
claimCase.vehicle?.carType as ClaimVehicleTypeV2,
|
||||
(claimCase.damage as any)?.selectedOuterParts,
|
||||
);
|
||||
const anglesKeys = ["front", "back", "left", "right"];
|
||||
const anglesCaptured = anglesKeys.filter((k) =>
|
||||
hasClaimCarAngleCapture(
|
||||
carAnglesData,
|
||||
damagedPartsData,
|
||||
k as ClaimCarAngleKey,
|
||||
),
|
||||
).length;
|
||||
const partsCaptured = selectedNorm.filter((sp) => {
|
||||
const ck = sp.catalogKey ?? catalogLikeKeyFromPart(sp);
|
||||
return hasDamagedPartCapture(damagedPartsData, ck, selectedNorm);
|
||||
}).length;
|
||||
|
||||
if (
|
||||
anglesCaptured >= 4 &&
|
||||
partsCaptured >= selectedNorm.length
|
||||
) {
|
||||
captureStepCompletedOnThisUpload = true;
|
||||
updateData["status"] = ClaimCaseStatus.UPLOADING_REQUIRED_DOCUMENTS;
|
||||
updateData["workflow.currentStep"] =
|
||||
ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS;
|
||||
updateData["workflow.nextStep"] =
|
||||
ClaimWorkflowStep.USER_SUBMISSION_COMPLETE;
|
||||
updateData.$push.history = [
|
||||
updateData.$push.history,
|
||||
{
|
||||
type: "STEP_COMPLETED",
|
||||
actor: {
|
||||
actorId: new Types.ObjectId(currentUserId),
|
||||
actorName: claimCase.owner?.fullName || "User",
|
||||
actorType: "user",
|
||||
},
|
||||
timestamp: new Date(),
|
||||
metadata: {
|
||||
stepKey: ClaimWorkflowStep.CAPTURE_PART_DAMAGES,
|
||||
description:
|
||||
"Angles, damaged parts, and capture-phase vehicle evidence (chassis, engine, metal plate) are complete. Please upload remaining required documents.",
|
||||
},
|
||||
},
|
||||
];
|
||||
updateData.$push["workflow.completedSteps"] =
|
||||
ClaimWorkflowStep.CAPTURE_PART_DAMAGES;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
allDocumentsUploaded = this.allV2OwnerDocumentsComplete(
|
||||
claimCase,
|
||||
@@ -4965,9 +5028,11 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
|
||||
const message = isCapturePhaseDocUpload
|
||||
? remaining > 0
|
||||
? `Document saved. ${remaining} capture-phase document(s) still required (chassis, engine, metal plate) before you can finish damage capture.`
|
||||
: "Document saved. All capture-phase documents are uploaded; finish car angles and part photos to proceed."
|
||||
? captureStepCompletedOnThisUpload
|
||||
? "Capture-phase documents and all damage captures are complete. Please proceed to upload the remaining required documents."
|
||||
: remaining > 0
|
||||
? `Document saved. ${remaining} capture-phase document(s) still required (chassis, engine, metal plate) before you can finish damage capture.`
|
||||
: "Document saved. All capture-phase documents are uploaded; finish car angles and part photos to proceed."
|
||||
: allDocumentsUploaded
|
||||
? "All documents uploaded successfully. Your claim is now ready for damage expert review."
|
||||
: `Document uploaded successfully. ${remaining} documents remaining.`;
|
||||
@@ -4978,7 +5043,9 @@ export class ClaimRequestManagementService {
|
||||
fileUrl,
|
||||
allDocumentsUploaded,
|
||||
currentStep: isCapturePhaseDocUpload
|
||||
? ClaimWorkflowStep.CAPTURE_PART_DAMAGES
|
||||
? captureStepCompletedOnThisUpload
|
||||
? ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS
|
||||
: ClaimWorkflowStep.CAPTURE_PART_DAMAGES
|
||||
: allDocumentsUploaded
|
||||
? ClaimWorkflowStep.USER_SUBMISSION_COMPLETE
|
||||
: ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
|
||||
Reference in New Issue
Block a user