forked from Yara724/api
Fix damaged-parts flow bug on carAngles
This commit is contained in:
@@ -84,6 +84,13 @@ import {
|
||||
normalizeResendPartKeys,
|
||||
partKeyAllowedForExpertResend,
|
||||
} from "src/helpers/claim-expert-resend";
|
||||
import {
|
||||
canonicalizeClaimCarAngleKey,
|
||||
getClaimCarAngleCaptureBlob,
|
||||
hasClaimCarAngleCapture,
|
||||
legacyAngleDamagedPartFieldKeysToUnset,
|
||||
type ClaimCarAngleKey,
|
||||
} from "src/helpers/claim-car-angle-media";
|
||||
import {
|
||||
ClaimVehicleTypeV2,
|
||||
OUTER_PARTS_BY_CAR_TYPE,
|
||||
@@ -4307,7 +4314,11 @@ export class ClaimRequestManagementService {
|
||||
key: angle.key,
|
||||
label_fa: angle.label_fa,
|
||||
label_en: angle.label_en,
|
||||
captured: !!hasCapture(claimCase.media?.carAngles as any, angle.key),
|
||||
captured: hasClaimCarAngleCapture(
|
||||
claimCase.media?.carAngles as any,
|
||||
claimCase.media?.damagedParts as any,
|
||||
angle.key as ClaimCarAngleKey,
|
||||
),
|
||||
}));
|
||||
|
||||
// Damaged parts from selected parts
|
||||
@@ -4735,8 +4746,24 @@ export class ClaimRequestManagementService {
|
||||
`Part "${body.captureKey}" was not requested by the damage expert for this resend.`,
|
||||
);
|
||||
}
|
||||
if (canonicalizeClaimCarAngleKey(body.captureKey)) {
|
||||
throw new BadRequestException(
|
||||
"During expert resend only damaged-part photos are allowed, not car angles (front/back/left/right).",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const angleCanon = canonicalizeClaimCarAngleKey(body.captureKey);
|
||||
if (body.captureType === "angle" && !angleCanon) {
|
||||
throw new BadRequestException(
|
||||
`Invalid angle captureKey "${body.captureKey}". Use one of: front, back, left, right.`,
|
||||
);
|
||||
}
|
||||
const treatAsAngle =
|
||||
!isResendCapture &&
|
||||
(body.captureType === "angle" ||
|
||||
(body.captureType === "part" && angleCanon !== null));
|
||||
|
||||
const fileUrl = buildFileLink(file.path);
|
||||
const captureData = {
|
||||
path: file.path,
|
||||
@@ -4748,7 +4775,7 @@ export class ClaimRequestManagementService {
|
||||
const updateData: any = {
|
||||
$push: {
|
||||
history: {
|
||||
type: body.captureType === 'angle' ? 'ANGLE_CAPTURED' : 'PART_CAPTURED',
|
||||
type: treatAsAngle ? "ANGLE_CAPTURED" : "PART_CAPTURED",
|
||||
actor: {
|
||||
actorId: new Types.ObjectId(currentUserId),
|
||||
actorName: claimCase.owner?.fullName || 'User',
|
||||
@@ -4758,19 +4785,33 @@ export class ClaimRequestManagementService {
|
||||
metadata: {
|
||||
captureType: body.captureType,
|
||||
captureKey: body.captureKey,
|
||||
...(treatAsAngle && angleCanon
|
||||
? { resolvedCarAngleKey: angleCanon }
|
||||
: {}),
|
||||
fileName: file.filename,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (body.captureType === 'angle') {
|
||||
updateData[`media.carAngles.${body.captureKey}`] = captureData;
|
||||
const selectedBefore = (claimCase.damage?.selectedParts || []) as string[];
|
||||
if (treatAsAngle && angleCanon) {
|
||||
updateData[`media.carAngles.${angleCanon}`] = captureData;
|
||||
const unsetFieldKeys = legacyAngleDamagedPartFieldKeysToUnset(
|
||||
angleCanon,
|
||||
body.captureKey,
|
||||
selectedBefore,
|
||||
);
|
||||
if (unsetFieldKeys.length) {
|
||||
updateData.$unset = {};
|
||||
for (const k of unsetFieldKeys) {
|
||||
updateData.$unset[`media.damagedParts.${k}`] = "";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
updateData[`media.damagedParts.${body.captureKey}`] = captureData;
|
||||
}
|
||||
|
||||
const selectedBefore = (claimCase.damage?.selectedParts || []) as string[];
|
||||
if (
|
||||
isResendCapture &&
|
||||
body.captureType === "part" &&
|
||||
@@ -4816,7 +4857,13 @@ export class ClaimRequestManagementService {
|
||||
const damagedPartsData = updatedClaim?.media?.damagedParts as any;
|
||||
const selectedParts = updatedClaim?.damage?.selectedParts || [];
|
||||
|
||||
const anglesCaptured = anglesKeys.filter(k => hasCapture(carAnglesData, k)).length;
|
||||
const anglesCaptured = anglesKeys.filter((k) =>
|
||||
hasClaimCarAngleCapture(
|
||||
carAnglesData,
|
||||
damagedPartsData,
|
||||
k as ClaimCarAngleKey,
|
||||
),
|
||||
).length;
|
||||
const partsCaptured = selectedParts.filter(p => hasCapture(damagedPartsData, p)).length;
|
||||
|
||||
const allCapturesComplete =
|
||||
@@ -5422,9 +5469,14 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
|
||||
const carAnglesData = claim.media?.carAngles as any;
|
||||
const damagedPartsForAngles = claim.media?.damagedParts as any;
|
||||
const carAngles: Record<string, { captured: boolean; url?: string }> = {};
|
||||
for (const k of ['front', 'back', 'left', 'right']) {
|
||||
const cap = hasCapture(carAnglesData, k);
|
||||
const cap = getClaimCarAngleCaptureBlob(
|
||||
carAnglesData,
|
||||
damagedPartsForAngles,
|
||||
k as ClaimCarAngleKey,
|
||||
) as { url?: string; path?: string } | undefined;
|
||||
carAngles[k] = {
|
||||
captured: !!cap,
|
||||
url: cap?.url || (cap?.path ? buildFileLink(cap.path) : undefined),
|
||||
|
||||
Reference in New Issue
Block a user