forked from Yara724/api
fix: recover saved photo uploads and lower car-body description minimum
Read saved document status from maps and plain objects, acknowledge verified document retries without replacing stored images, and preserve upload authorization and resend behavior. Lower the car-body narrative minimum to 30 characters with Persian errors and boundary regression coverage.
This commit is contained in:
@@ -9308,7 +9308,8 @@ export class ClaimRequestManagementService {
|
||||
];
|
||||
|
||||
const requiredDocuments = requiredDocsDefinition.map((doc) => {
|
||||
const docData = (claimCase.requiredDocuments as any)?.get?.(doc.key);
|
||||
const docData = (claimCase.requiredDocuments as any)?.get?.(doc.key) ??
|
||||
(claimCase.requiredDocuments as any)?.[doc.key];
|
||||
return {
|
||||
key: doc.key,
|
||||
label_fa: doc.label_fa,
|
||||
@@ -9546,9 +9547,31 @@ export class ClaimRequestManagementService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* V2 API: Upload required document
|
||||
*/
|
||||
/** Reuse a confirmed stored document, never an uploaded flag without file evidence. */
|
||||
private existingDocumentUploadResult(
|
||||
claim: any,
|
||||
key: string,
|
||||
): UploadRequiredDocumentV2ResponseDto | undefined {
|
||||
const doc =
|
||||
claim.requiredDocuments?.get?.(key) ?? claim.requiredDocuments?.[key];
|
||||
if (!doc?.uploaded) return undefined;
|
||||
const path = typeof doc.filePath === 'string' ? doc.filePath.trim() : '';
|
||||
const url = typeof doc.fileUrl === 'string' ? doc.fileUrl.trim() : '';
|
||||
if (!path && !url) return undefined;
|
||||
return {
|
||||
claimRequestId: String(claim._id),
|
||||
documentKey: key,
|
||||
fileUrl: path ? buildFileLink(path) : url,
|
||||
alreadyUploaded: true,
|
||||
allDocumentsUploaded: (claim.workflow?.completedSteps ?? []).includes(
|
||||
ClaimWorkflowStep.UPLOAD_REQUIRED_DOCUMENTS,
|
||||
),
|
||||
currentStep: claim.workflow?.currentStep ?? '',
|
||||
message: 'تصویر این مدرک قبلاً ثبت شده است؛ میتوانید ادامه دهید.',
|
||||
};
|
||||
}
|
||||
|
||||
/** V2 API: Upload required document. Initial-upload retries reuse stored evidence. */
|
||||
async uploadRequiredDocumentV2(
|
||||
claimRequestId: string,
|
||||
body: UploadRequiredDocumentV2Dto,
|
||||
@@ -9584,6 +9607,14 @@ export class ClaimRequestManagementService {
|
||||
|
||||
const step = claimCase.workflow?.currentStep;
|
||||
const isResendUpload = step === ClaimWorkflowStep.USER_EXPERT_RESEND;
|
||||
if (
|
||||
!isResendUpload &&
|
||||
claimCase.status !== ClaimCaseStatus.WAITING_FOR_USER_RESEND &&
|
||||
!options?.v3InPersonFlow
|
||||
) {
|
||||
const existing = this.existingDocumentUploadResult(claimCase, body.documentKey);
|
||||
if (existing) return existing;
|
||||
}
|
||||
const isOptionalDocument =
|
||||
body.documentKey === ClaimRequiredDocumentType.ACCIDENT_SKETCH;
|
||||
const isCapturePhaseDocUpload =
|
||||
@@ -9678,17 +9709,8 @@ export class ClaimRequestManagementService {
|
||||
);
|
||||
}
|
||||
|
||||
// Initial flow: each document once. Expert resend and v3 in-person: allow replacement.
|
||||
if (!isResendUpload && !options?.v3InPersonFlow) {
|
||||
const existingDoc =
|
||||
(claimCase.requiredDocuments as any)?.get?.(body.documentKey) ??
|
||||
(claimCase.requiredDocuments as any)?.[body.documentKey];
|
||||
if (existingDoc?.uploaded) {
|
||||
throw new ConflictException(
|
||||
`Document ${body.documentKey} has already been uploaded`,
|
||||
);
|
||||
}
|
||||
}
|
||||
// A confirmed initial upload was returned above. Incomplete references may
|
||||
// be repaired here; expert-requested resends and in-person replacements remain allowed.
|
||||
|
||||
const fileUrl = buildFileLink(file.path);
|
||||
|
||||
@@ -12039,6 +12061,27 @@ export class ClaimRequestManagementService {
|
||||
isCapturePhaseDamagedPartyDocKey(body.documentKey) ||
|
||||
isGuiltyDamageAreaDoc;
|
||||
|
||||
// A response may have been lost after the last capture document advanced
|
||||
// the workflow. Reuse that saved evidence after the usual owner/tenant checks.
|
||||
if (
|
||||
isCaptureDoc &&
|
||||
claimCase.status !== ClaimCaseStatus.WAITING_FOR_USER_RESEND &&
|
||||
claimCase.workflow?.currentStep !== ClaimWorkflowStep.CAPTURE_PART_DAMAGES &&
|
||||
this.claimV3StepCompleted(claimCase, ClaimWorkflowStep.CAPTURE_PART_DAMAGES)
|
||||
) {
|
||||
const existing = this.existingDocumentUploadResult(claimCase, body.documentKey);
|
||||
if (existing) {
|
||||
const effectiveUserId = await this.resolveClaimEffectiveUserId(
|
||||
claimCase, currentUserId, actor?.role,
|
||||
);
|
||||
await this.assertEffectiveUserIsDamagedPartyOnClaim(
|
||||
claimCase, effectiveUserId, actor as { username?: string },
|
||||
'Only the claim owner can upload documents',
|
||||
);
|
||||
return existing;
|
||||
}
|
||||
}
|
||||
|
||||
if (isCaptureDoc) {
|
||||
this.assertV3ClaimPartsPhase(blame);
|
||||
this.assertV3ClaimWorkflowStep(
|
||||
|
||||
Reference in New Issue
Block a user