forked from Yara724/api
YARA-1135
This commit is contained in:
@@ -84,6 +84,7 @@ import { WorkflowStepDbService } from "src/workflow-step-management/entities/db-
|
||||
import { WorkflowStepModel } from "src/workflow-step-management/entities/schema/workflow-step.schema";
|
||||
import { BlameStatus } from "src/Types&Enums/blame-request-management/blameStatus.enum";
|
||||
import { CaseStatus } from "src/Types&Enums/blame-request-management/caseStatus.enum";
|
||||
import { BusinessRuleException, BusinessErrorCode } from "src/expert-claim/exceptions/business-rule.exception";
|
||||
import { ExpertFileActivityDbService } from "src/users/entities/db-service/expert-file-activity.db.service";
|
||||
import {
|
||||
ExpertFileActivityType,
|
||||
@@ -10360,7 +10361,17 @@ export class RequestManagementService {
|
||||
|
||||
this.assertFileMakerApprovalAccess(claim, fileMaker);
|
||||
|
||||
if (claim.status !== ClaimCaseStatus.WAITING_FOR_FILE_MAKER_APPROVAL) {
|
||||
// After 2 rejections the claim is in WAITING_FOR_DAMAGE_EXPERT (forced-approve
|
||||
// path); any other status is still an error.
|
||||
const rejectionCount = (claim as any).fileMakerRejectionCount ?? 0;
|
||||
const forcedApprove =
|
||||
rejectionCount >= 2 &&
|
||||
claim.status === ClaimCaseStatus.WAITING_FOR_DAMAGE_EXPERT;
|
||||
|
||||
if (
|
||||
claim.status !== ClaimCaseStatus.WAITING_FOR_FILE_MAKER_APPROVAL &&
|
||||
!forcedApprove
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
`Claim must be in WAITING_FOR_FILE_MAKER_APPROVAL status to approve. Current: ${claim.status}`,
|
||||
);
|
||||
@@ -10404,11 +10415,14 @@ export class RequestManagementService {
|
||||
}
|
||||
|
||||
/**
|
||||
* V5: FileMaker rejects the completed claim back to expert review.
|
||||
* V5: FileMaker rejects the completed claim back to FileReviewer for correction.
|
||||
*
|
||||
* Moves claim from WAITING_FOR_FILE_MAKER_APPROVAL → WAITING_FOR_DAMAGE_EXPERT
|
||||
* so the FileReviewer can re-lock it and adjust the damage assessment or
|
||||
* restart the back-and-forth with the user.
|
||||
* Allowed at most 2 times per claim lifetime. On the 3rd attempt the endpoint
|
||||
* returns 422 FILE_MAKER_REJECTION_LIMIT_EXCEEDED and the FileMaker must approve.
|
||||
*
|
||||
* Transition (both blame + claim are updated atomically):
|
||||
* claim: WAITING_FOR_FILE_MAKER_APPROVAL → WAITING_FOR_DAMAGE_EXPERT
|
||||
* blame: (any status) → WAITING_FOR_FILE_REVIEWER
|
||||
*/
|
||||
async fileMakerRejectV5(
|
||||
fileMaker: any,
|
||||
@@ -10418,6 +10432,7 @@ export class RequestManagementService {
|
||||
claimRequestId: string;
|
||||
publicId: string;
|
||||
status: string;
|
||||
fileMakerRejectionCount: number;
|
||||
message: string;
|
||||
}> {
|
||||
const claim = await this.claimCaseDbService.findById(claimRequestId);
|
||||
@@ -10431,14 +10446,26 @@ export class RequestManagementService {
|
||||
);
|
||||
}
|
||||
|
||||
const currentRejections = (claim as any).fileMakerRejectionCount ?? 0;
|
||||
if (currentRejections >= 2) {
|
||||
throw new BusinessRuleException(
|
||||
BusinessErrorCode.FILE_MAKER_REJECTION_LIMIT_EXCEEDED,
|
||||
"This claim has already been rejected twice. You must approve it now — no further rejections are allowed.",
|
||||
);
|
||||
}
|
||||
|
||||
const newRejectionCount = currentRejections + 1;
|
||||
const actorName = `${fileMaker.firstName || ""} ${fileMaker.lastName || ""}`.trim();
|
||||
|
||||
await this.claimCaseDbService.findByIdAndUpdate(claimRequestId, {
|
||||
$set: {
|
||||
status: ClaimCaseStatus.FILE_MAKER_REJECTED,
|
||||
status: ClaimCaseStatus.WAITING_FOR_DAMAGE_EXPERT,
|
||||
claimStatus: ClaimStatus.NEEDS_REVISION,
|
||||
fileMakerRejectionCount: newRejectionCount,
|
||||
fileMakerRejectionReason: reason ?? null,
|
||||
"workflow.currentStep": ClaimWorkflowStep.EXPERT_DAMAGE_ASSESSMENT,
|
||||
"workflow.nextStep": ClaimWorkflowStep.EXPERT_DAMAGE_ASSESSMENT,
|
||||
"workflow.locked": false,
|
||||
},
|
||||
$push: {
|
||||
history: {
|
||||
@@ -10449,17 +10476,43 @@ export class RequestManagementService {
|
||||
actorType: "file_maker",
|
||||
},
|
||||
timestamp: new Date(),
|
||||
metadata: { reason: reason ?? null },
|
||||
metadata: { reason: reason ?? null, rejectionCount: newRejectionCount },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Reset blame back to WAITING_FOR_FILE_REVIEWER so the reviewer's list
|
||||
// query (which looks for that status + assignedFileReviewerId) surfaces it.
|
||||
if (claim.blameRequestId) {
|
||||
await this.blameRequestDbService.findByIdAndUpdate(
|
||||
String(claim.blameRequestId),
|
||||
{
|
||||
$set: { status: CaseStatus.WAITING_FOR_FILE_REVIEWER },
|
||||
$push: {
|
||||
history: {
|
||||
type: "V5_FILE_MAKER_REJECTED_BLAME_RESET",
|
||||
actor: {
|
||||
actorId: new Types.ObjectId(fileMaker.sub),
|
||||
actorName,
|
||||
actorType: "file_maker",
|
||||
},
|
||||
timestamp: new Date(),
|
||||
metadata: { claimRequestId, reason: reason ?? null },
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
claimRequestId,
|
||||
publicId: claim.publicId,
|
||||
status: ClaimCaseStatus.FILE_MAKER_REJECTED,
|
||||
status: ClaimCaseStatus.WAITING_FOR_DAMAGE_EXPERT,
|
||||
fileMakerRejectionCount: newRejectionCount,
|
||||
message:
|
||||
"Claim rejected by FileMaker. FileReviewer can re-lock the claim and adjust the damage assessment or restart the user interaction.",
|
||||
newRejectionCount >= 2
|
||||
? "Claim rejected by FileMaker (2nd rejection — next action must be approval). FileReviewer can re-lock and adjust the assessment."
|
||||
: "Claim rejected by FileMaker. FileReviewer can re-lock the claim and adjust the damage assessment or restart the user interaction.",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user