1
0
forked from Yara724/api

Merge pull request 'blame status agreement fixed' (#30) from s.hajizadeh/yara724api:main into main

Reviewed-on: Yara724/api#30
This commit is contained in:
2026-04-20 11:22:04 +03:30

View File

@@ -1154,18 +1154,13 @@ export class RequestManagementService {
(party.statement as any).lightCondition = body.lightCondition; (party.statement as any).lightCondition = body.lightCondition;
} }
// If second party finished description, were ready for expert flow. const isSecondThirdParty =
if (stepKey === WorkflowStep.SECOND_DESCRIPTION) {
req.status = CaseStatus.WAITING_FOR_EXPERT;
}
await this.advanceWorkflowToNext(req, stepKey);
if (
stepKey === WorkflowStep.SECOND_DESCRIPTION && stepKey === WorkflowStep.SECOND_DESCRIPTION &&
req.type === BlameRequestType.THIRD_PARTY && req.type === BlameRequestType.THIRD_PARTY;
!(req as any).expert?.decision?.guiltyPartyId 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( const built = buildMutualAgreementExpertDecision(
(req as any).toObject (req as any).toObject
? (req as any).toObject() ? (req as any).toObject()
@@ -1174,6 +1169,40 @@ export class RequestManagementService {
if (built) { if (built) {
if (!(req as any).expert) (req as any).expert = {}; if (!(req as any).expert) (req as any).expert = {};
(req as any).expert.decision = built as any; (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, actorName: user?.fullName,
actorType: "user", actorType: "user",
}, },
metadata: { role }, metadata: {
role,
...(closedByMutualAgreement
? { mutualAgreementCaseComplete: true, closedWithoutExpert: true }
: {}),
},
} as any); } as any);
await (req as any).save(); await (req as any).save();