Fix workflow steps

This commit is contained in:
2026-05-01 16:01:08 +03:30
parent d9dc4ecdff
commit 0bb13f4596
5 changed files with 123 additions and 41 deletions

View File

@@ -28,7 +28,10 @@ import { UserSignatureResponseDto } from "./dto/user-signature.dto";
import { ResendItemType } from "src/Types&Enums/blame-request-management/resendItemType.enum";
import {
buildResendItemsWithUi,
cloneResendUploadedDocuments,
isResendPartyItemSatisfied,
normalizeResendRequestedItemKey,
normalizeResendRequestedItemsList,
} from "src/Types&Enums/blame-request-management/resend-item-ui";
import { ClaimCaseDbService } from "src/claim-request-management/entites/db-service/claim-case.db.service";
import { ClaimCaseStatus } from "src/Types&Enums/claim-request-management/claim-case-status.enum";
@@ -6040,14 +6043,12 @@ export class RequestManagementService {
);
}
const items = (userResendRequest.requestedItems || []) as string[];
const items = normalizeResendRequestedItemsList(
userResendRequest.requestedItems as string[],
);
const row = userResendRequest as any;
const merged = {
uploadedDocuments: {
...(typeof row.uploadedDocuments === "object" && row.uploadedDocuments
? { ...row.uploadedDocuments }
: {}),
},
uploadedDocuments: cloneResendUploadedDocuments(row.uploadedDocuments),
resendVoiceId: row.resendVoiceId,
resendVideoId: row.resendVideoId,
userTextDescription: row.userTextDescription,
@@ -6056,7 +6057,7 @@ export class RequestManagementService {
return {
requestId: String(request._id),
requestedItems: userResendRequest.requestedItems,
requestedItems: items,
description: userResendRequest.description || "",
completed: userResendRequest.completed || false,
requestedItemsUi: buildResendItemsWithUi(items),
@@ -6122,22 +6123,26 @@ export class RequestManagementService {
}
const userResendRequest = resendParties[resendIndex];
const requestedItems = userResendRequest.requestedItems || [];
const requestedItems = normalizeResendRequestedItemsList(
userResendRequest.requestedItems as string[],
);
if (requestedItems.length === 0) {
throw new BadRequestException(
"No valid requested items are configured for your party resend. Please contact support.",
);
}
const row = userResendRequest as any;
const mergedRow = {
uploadedDocuments: {
...(typeof row.uploadedDocuments === "object" && row.uploadedDocuments
? { ...row.uploadedDocuments }
: {}),
},
uploadedDocuments: cloneResendUploadedDocuments(row.uploadedDocuments),
resendVoiceId: row.resendVoiceId,
resendVideoId: row.resendVideoId,
userTextDescription: row.userTextDescription,
};
const hasAnyFile = Object.keys(files || {}).some((fieldName) => {
const fileArray = files[fieldName as keyof typeof files];
const safeFiles = files || {};
const hasAnyFile = Object.keys(safeFiles).some((fieldName) => {
const fileArray = safeFiles[fieldName as keyof typeof safeFiles];
return fileArray && fileArray.length > 0 && fileArray[0];
});
const descTrim =
@@ -6147,7 +6152,7 @@ export class RequestManagementService {
if (!hasAnyFile && !sendingDescription) {
throw new BadRequestException(
"Provide at least one requested file or a text description when description was requested.",
"Provide at least one file for a requested item and/or the text description when the expert asked for a description.",
);
}
@@ -6162,19 +6167,20 @@ export class RequestManagementService {
uploadedItems.push(ResendItemType.DESCRIPTION);
}
for (const fieldName in files) {
const fileArray = files[fieldName as keyof typeof files];
for (const fieldName of Object.keys(safeFiles)) {
const fileArray = safeFiles[fieldName as keyof typeof safeFiles];
if (!fileArray || fileArray.length === 0) continue;
const file = fileArray[0];
if (!requestedItems.includes(fieldName)) {
const canonKey = normalizeResendRequestedItemKey(fieldName);
if (!canonKey || !requestedItems.includes(canonKey)) {
throw new BadRequestException(
`${fieldName} was not requested. Requested items: ${requestedItems.join(", ")}`,
`${fieldName} was not requested or is not a valid resend field. Requested items: ${requestedItems.join(", ")}`,
);
}
if (fieldName === "voice") {
if (canonKey === ResendItemType.VOICE) {
const voiceDoc = await this.blameVoiceDbService.create({
path: file.path,
requestId: new Types.ObjectId(requestId),
@@ -6188,8 +6194,8 @@ export class RequestManagementService {
`expert.resend.parties.${resendIndex}.resendVoiceId`
] = (voiceDoc as any)._id;
mergedRow.resendVoiceId = (voiceDoc as any)._id;
uploadedItems.push(fieldName);
} else if (fieldName === "video") {
uploadedItems.push(canonKey);
} else if (canonKey === ResendItemType.VIDEO) {
const videoDoc = await this.blameVideoDbService.create({
path: file.path,
requestId: new Types.ObjectId(requestId),
@@ -6201,9 +6207,9 @@ export class RequestManagementService {
`expert.resend.parties.${resendIndex}.resendVideoId`
] = (videoDoc as any)._id;
mergedRow.resendVideoId = (videoDoc as any)._id;
uploadedItems.push(fieldName);
uploadedItems.push(canonKey);
} else {
const docType = fieldName as BlameDocumentType;
const docType = canonKey as BlameDocumentType;
const doc = await this.blameDocumentDbService.create({
path: file.path,
requestId: new Types.ObjectId(requestId),
@@ -6211,16 +6217,16 @@ export class RequestManagementService {
documentType: docType,
});
updatePayload.$set[
`expert.resend.parties.${resendIndex}.uploadedDocuments.${fieldName}`
`expert.resend.parties.${resendIndex}.uploadedDocuments.${canonKey}`
] = (doc as any)._id;
mergedRow.uploadedDocuments[fieldName] = (doc as any)._id;
uploadedItems.push(fieldName);
mergedRow.uploadedDocuments[canonKey] = (doc as any)._id;
uploadedItems.push(canonKey);
}
}
const allItemsCompleted = (requestedItems as string[]).every((item) =>
isResendPartyItemSatisfied(item, mergedRow),
);
const allItemsCompleted =
requestedItems.length > 0 &&
requestedItems.every((item) => isResendPartyItemSatisfied(item, mergedRow));
if (allItemsCompleted) {
updatePayload.$set[`expert.resend.parties.${resendIndex}.completed`] = true;
@@ -6231,7 +6237,7 @@ export class RequestManagementService {
await this.blameRequestDbService.findByIdAndUpdate(requestId, updatePayload);
const updatedRequest = await this.blameRequestDbService.findById(requestId);
const allPartiesCompleted = updatedRequest.expert?.resend?.parties?.every(
const allPartiesCompleted = updatedRequest?.expert?.resend?.parties?.every(
(p) => p.completed,
);

View File

@@ -399,6 +399,11 @@ export class RequestManagementV2Controller {
description:
"Text description when expert requested ResendItemType.description",
},
textDescription: {
type: "string",
description:
"Alias for `description` (same semantics); either field may be used.",
},
},
},
})
@@ -442,12 +447,18 @@ export class RequestManagementV2Controller {
video?: Express.Multer.File[];
},
@Body("description") description?: string,
@Body("textDescription") textDescription?: string,
) {
const descCandidates = [description, textDescription]
.map((x) => (x != null ? String(x).trim() : ""))
.filter((s) => s.length > 0);
const mergedDescription =
descCandidates.length > 0 ? descCandidates[0] : undefined;
return this.requestManagementService.uploadResendDocumentsV2(
requestId,
user.sub,
files,
description,
mergedDescription,
);
}
}