blame status agreement fixed

This commit is contained in:
2026-04-20 11:19:49 +03:30
parent a71c4ea980
commit 9463142ecf

View File

@@ -1154,13 +1154,41 @@ export class RequestManagementService {
(party.statement as any).lightCondition = body.lightCondition;
}
// If second party finished description, were ready for expert flow.
const isSecondThirdParty =
stepKey === WorkflowStep.SECOND_DESCRIPTION &&
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()
: { ...req },
);
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 &&
@@ -1176,6 +1204,7 @@ export class RequestManagementService {
(req as any).expert.decision = built as any;
}
}
}
if (!Array.isArray(req.history)) req.history = [];
req.history.push({
@@ -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();