Added vin inquiry for v6, fixed new damaged part for v4

This commit is contained in:
SepehrYahyaee
2026-08-10 13:48:05 +03:30
parent ca7200e17d
commit 6791c71809
6 changed files with 292 additions and 44 deletions

View File

@@ -163,6 +163,7 @@ import {
CAPTURE_PHASE_DAMAGED_PARTY_DOC_KEYS,
capturePhaseSequenceMessage,
getClaimCaptureProgress,
GUILTY_DAMAGE_AREA_DOC_KEY,
isCapturePhaseDamagedPartyDocKey,
isClaimCaptureStepComplete,
OPTIONAL_CAPTURE_PHASE_DOC_KEYS_V4V5,
@@ -9073,7 +9074,7 @@ export class ClaimRequestManagementService {
file: Express.Multer.File,
currentUserId: string,
actor?: { sub: string; role?: string },
options?: { v3InPersonFlow?: boolean; skipMetalPlate?: boolean; requiresFileMakerApproval?: boolean },
options?: { v3InPersonFlow?: boolean; skipMetalPlate?: boolean; requiresFileMakerApproval?: boolean; includeGuiltyDamageArea?: boolean },
): Promise<UploadRequiredDocumentV2ResponseDto> {
try {
const claimCase = await this.claimCaseDbService.findById(claimRequestId);
@@ -9099,7 +9100,9 @@ export class ClaimRequestManagementService {
const isResendUpload = step === ClaimWorkflowStep.USER_EXPERT_RESEND;
const isCapturePhaseDocUpload =
step === ClaimWorkflowStep.CAPTURE_PART_DAMAGES &&
isCapturePhaseDamagedPartyDocKey(body.documentKey);
(isCapturePhaseDamagedPartyDocKey(body.documentKey) ||
(options?.includeGuiltyDamageArea &&
(body.documentKey as string) === GUILTY_DAMAGE_AREA_DOC_KEY));
if (!isResendUpload) {
if (
@@ -9249,17 +9252,20 @@ export class ClaimRequestManagementService {
const afterThis = (k: string) =>
k === body.documentKey ||
this.isRequiredDocumentUploadedOnClaim(claimCase, k);
remaining = CAPTURE_PHASE_DAMAGED_PARTY_DOC_KEYS.filter(
(k) => {
if (options?.skipMetalPlate && OPTIONAL_CAPTURE_PHASE_DOC_KEYS_V4V5.includes(k as any)) return false;
return !afterThis(k);
},
).length;
const captureKeysForCount: string[] = [
...CAPTURE_PHASE_DAMAGED_PARTY_DOC_KEYS,
...(options?.includeGuiltyDamageArea ? [GUILTY_DAMAGE_AREA_DOC_KEY] : []),
];
remaining = captureKeysForCount.filter((k) => {
if (options?.skipMetalPlate && OPTIONAL_CAPTURE_PHASE_DOC_KEYS_V4V5.includes(k as any)) return false;
return !afterThis(k);
}).length;
if (remaining === 0) {
const progressAfterDoc = getClaimCaptureProgress(claimCase, {
assumeCapturePhaseDocKey: body.documentKey,
skipMetalPlate: options?.skipMetalPlate,
includeGuiltyDamageArea: options?.includeGuiltyDamageArea,
});
if (
@@ -11241,6 +11247,13 @@ export class ClaimRequestManagementService {
base: GetCaptureRequirementsV2ResponseDto,
): GetCaptureRequirementsV2ResponseDto {
const skipMetalPlate = !!(blame as any)?.isMadeByFileMaker;
// V4 = FileMaker flow without a secondary FileMaker approval step
const isV4 =
!!(blame as any)?.isMadeByFileMaker &&
!(claimCase as any)?.requiresFileMakerApproval;
const isCarBody =
blame?.type === BlameRequestType.CAR_BODY ||
(blame as any)?.type === "CAR_BODY";
// For V4/V5 files strip metal-plate keys from the base response entirely
// so they never appear in any phase — the front-end should not show them.
@@ -11316,6 +11329,51 @@ export class ClaimRequestManagementService {
d.preferUploadDuringCapture &&
!(skipMetalPlate && OPTIONAL_CAPTURE_PHASE_DOC_KEYS_V4V5.includes(d.key as any)),
);
// V4 THIRD_PARTY only: guilty_damage_area is uploaded via upload-document
// after all car angles are captured (last item in the documents phase).
// It also appears in damagedParts so the expert sees it labelled as a
// damaged-part capture.
if (isV4 && !isCarBody) {
const guiltyAreaUploaded = this.isRequiredDocumentUploadedOnClaim(
claimCase,
GUILTY_DAMAGE_AREA_DOC_KEY,
);
const guiltyAreaDoc = {
key: GUILTY_DAMAGE_AREA_DOC_KEY,
label_fa: "تصویر نقطه آسیب‌دیده مقصر",
label_en: "Guilty Car Damaged Area",
category: "guilty_party",
uploaded: guiltyAreaUploaded,
preferUploadDuringCapture: true,
};
const guiltyAreaPart = {
id: null as any,
key: GUILTY_DAMAGE_AREA_DOC_KEY,
name: GUILTY_DAMAGE_AREA_DOC_KEY,
side: "",
label_fa: "تصویر نقطه آسیب‌دیده مقصر",
label_en: "Guilty Car Damaged Area",
captured: guiltyAreaUploaded,
};
const captureProgress = getClaimCaptureProgress(claimCase, {
skipMetalPlate,
includeGuiltyDamageArea: true,
});
return {
...base,
requiredDocuments: [...capturePhaseDocs, guiltyAreaDoc],
damagedParts: [...base.damagedParts, guiltyAreaPart],
totalRemaining: captureProgress.capturePhaseDocsRemaining,
progress: {
...base.progress,
capturePhaseDocsRemaining: captureProgress.capturePhaseDocsRemaining,
},
};
}
return {
...base,
requiredDocuments: capturePhaseDocs,
@@ -11355,8 +11413,21 @@ export class ClaimRequestManagementService {
}
const blame = await this.assertV3InPersonClaim(claimCase);
const skipMetalPlate = !!(blame as any).isMadeByFileMaker;
const isV4FileMaker =
!!(blame as any)?.isMadeByFileMaker &&
!(claimCase as any)?.requiresFileMakerApproval;
const isCarBodyBlame =
blame?.type === BlameRequestType.CAR_BODY ||
(blame as any)?.type === "CAR_BODY";
const isCaptureDoc = isCapturePhaseDamagedPartyDocKey(body.documentKey);
// guilty_damage_area is an extra capture-phase doc key for V4 THIRD_PARTY
const isGuiltyDamageAreaDoc =
(body.documentKey as string) === GUILTY_DAMAGE_AREA_DOC_KEY &&
isV4FileMaker &&
!isCarBodyBlame;
const isCaptureDoc =
isCapturePhaseDamagedPartyDocKey(body.documentKey) || isGuiltyDamageAreaDoc;
if (isCaptureDoc) {
this.assertV3ClaimPartsPhase(blame);
@@ -11375,7 +11446,10 @@ export class ClaimRequestManagementService {
"Complete outer and other part selection before capture-phase vehicle documents.",
);
}
const captureProgress = getClaimCaptureProgress(claimCase, { skipMetalPlate });
const captureProgress = getClaimCaptureProgress(claimCase, {
skipMetalPlate,
includeGuiltyDamageArea: isGuiltyDamageAreaDoc,
});
if (!captureProgress.partsComplete) {
throw new BadRequestException(
"Upload photos for all selected damaged parts before chassis or engine photos.",
@@ -11403,7 +11477,12 @@ export class ClaimRequestManagementService {
file,
currentUserId,
actor,
{ v3InPersonFlow: true, skipMetalPlate, requiresFileMakerApproval: !!(claimCase as any).requiresFileMakerApproval },
{
v3InPersonFlow: true,
skipMetalPlate,
requiresFileMakerApproval: !!(claimCase as any).requiresFileMakerApproval,
includeGuiltyDamageArea: isGuiltyDamageAreaDoc,
},
);
}
@@ -11463,30 +11542,6 @@ export class ClaimRequestManagementService {
const result = await this.selectOuterPartsV2(claimRequestId, body, currentUserId, actor);
// V4 THIRD_PARTY only: append a synthetic "guilty damage area" entry to
// damage.selectedParts so the FileReviewer must capture one photo of the
// guilty party's damaged spot during the CAPTURE_PART_DAMAGES phase.
// selectOuterPartsV2 uses $set on damage.selectedParts, so we append here
// with a separate $push after the V2 write completes.
const isV4 =
!!(blame as any)?.isMadeByFileMaker &&
!(refreshed as any)?.requiresFileMakerApproval;
const isCarBodyBlame =
blame?.type === BlameRequestType.CAR_BODY ||
(blame as any)?.type === "CAR_BODY";
if (isV4 && !isCarBodyBlame) {
await this.claimCaseDbService.findByIdAndUpdate(claimRequestId, {
$push: {
"damage.selectedParts": {
id: null,
name: "guilty_damage_area",
side: "",
label_fa: "تصویر نقطه آسیب‌دیده مقصر",
},
},
});
}
return result;
}