From 9463142ecf71a2b3e687105508eda477ebf5373f Mon Sep 17 00:00:00 2001 From: "s.hajizadeh" Date: Mon, 20 Apr 2026 11:19:49 +0330 Subject: [PATCH] blame status agreement fixed --- .../request-management.service.ts | 58 +++++++++++++++---- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/src/request-management/request-management.service.ts b/src/request-management/request-management.service.ts index 1f7500e..36bb5e5 100644 --- a/src/request-management/request-management.service.ts +++ b/src/request-management/request-management.service.ts @@ -1154,18 +1154,13 @@ export class RequestManagementService { (party.statement as any).lightCondition = body.lightCondition; } - // If second party finished description, we’re ready for expert flow. - if (stepKey === WorkflowStep.SECOND_DESCRIPTION) { - req.status = CaseStatus.WAITING_FOR_EXPERT; - } - - await this.advanceWorkflowToNext(req, stepKey); - - if ( + const isSecondThirdParty = stepKey === WorkflowStep.SECOND_DESCRIPTION && - req.type === BlameRequestType.THIRD_PARTY && - !(req as any).expert?.decision?.guiltyPartyId - ) { + req.type === BlameRequestType.THIRD_PARTY; + let closedByMutualAgreement = false; + + // THIRD_PARTY + AGREED: guilt/damage already implied by first-party confession — no field expert needed. + if (isSecondThirdParty && req.blameStatus === BlameStatus.AGREED) { const built = buildMutualAgreementExpertDecision( (req as any).toObject ? (req as any).toObject() @@ -1174,6 +1169,40 @@ export class RequestManagementService { if (built) { if (!(req as any).expert) (req as any).expert = {}; (req as any).expert.decision = built as any; + const completed = Array.isArray(req.workflow.completedSteps) + ? req.workflow.completedSteps + : []; + if (!completed.includes(stepKey)) completed.push(stepKey); + if (!completed.includes(WorkflowStep.COMPLETED as any)) { + completed.push(WorkflowStep.COMPLETED as any); + } + req.workflow.completedSteps = completed; + req.workflow.currentStep = WorkflowStep.COMPLETED; + req.workflow.nextStep = undefined; + req.status = CaseStatus.COMPLETED; + closedByMutualAgreement = true; + } + } + + if (!closedByMutualAgreement) { + if (stepKey === WorkflowStep.SECOND_DESCRIPTION) { + req.status = CaseStatus.WAITING_FOR_EXPERT; + } + await this.advanceWorkflowToNext(req, stepKey); + if ( + stepKey === WorkflowStep.SECOND_DESCRIPTION && + req.type === BlameRequestType.THIRD_PARTY && + !(req as any).expert?.decision?.guiltyPartyId + ) { + const built = buildMutualAgreementExpertDecision( + (req as any).toObject + ? (req as any).toObject() + : { ...req }, + ); + if (built) { + if (!(req as any).expert) (req as any).expert = {}; + (req as any).expert.decision = built as any; + } } } @@ -1187,7 +1216,12 @@ export class RequestManagementService { actorName: user?.fullName, actorType: "user", }, - metadata: { role }, + metadata: { + role, + ...(closedByMutualAgreement + ? { mutualAgreementCaseComplete: true, closedWithoutExpert: true } + : {}), + }, } as any); await (req as any).save();