Re_Backend/docs/PLAN_STATUS_REFINEMENT.md

62 lines
2.3 KiB
Markdown

# Implementation Plan: Status Ambiguity Refinement
This document outlines the specific code changes required to implement the **Dual-Key Status Architecture**.
## 1. Goal
Decouple the business outcome (Approved/Rejected) from the lifecycle state (Open/Closed/Draft) to ensure transparency in finalized requests.
## 2. Schema Changes
### `WorkflowRequest.schema.ts`
- **Update `status` Enum**: Remove `CLOSED` and `CANCELLED`.
- **Add `workflowState`**:
- Type: `String`
- Enum: `['DRAFT', 'OPEN', 'CLOSED']`
- Default: `'DRAFT'`
- Index: `true`
## 3. Logic Updates
### A. Workflow Creation (`WorkflowService.createWorkflow`)
- Initialize `status: 'DRAFT'`.
- Initialize `workflowState: 'DRAFT'`.
- Set `isDraft: true`.
### B. Workflow Submission (`WorkflowService.submitRequest`)
- Update `status: 'PENDING'`.
- Update `workflowState: 'OPEN'`.
- Set `isDraft: false`.
### C. Approval/Rejection (`WorkflowService`)
- When approved at a level: Keep `status` as `IN_PROGRESS` or set to `APPROVED` if final.
- When rejected: Set `status` to `REJECTED`.
- **Crucial**: The `workflowState` remains `OPEN` during these actions.
### D. Finalization (`ConclusionController.finalizeConclusion`)
- **Current Behavior**: Sets `status = 'CLOSED'`.
- **New Behavior**:
- Sets `workflowState = 'CLOSED'`.
- **Does NOT** change `status`. The `status` will remain `APPROVED` or `REJECTED`.
- Sets `closureDate = new Date()`.
### E. Pause Logic (`PauseMongoService`)
- Set `status = 'PAUSED'`.
- Set `isPaused = true`.
- Keep `workflowState = 'OPEN'`.
## 4. Dashboard & KPI Updates (`DashboardMongoService`)
### `getRequestStats`
- Update the aggregation pipeline to group by `workflowState`.
- `OPEN` category will now include all requests where `workflowState == 'OPEN'`.
- `CLOSED` category will now include all requests where `workflowState == 'CLOSED'`.
- This ensures that a "Closed" count on the dashboard includes both Approved and Rejected requests that have been finalized.
### `getTATEfficiency`
- Update match criteria to `workflowState: 'CLOSED'` instead of `status: 'CLOSED'`.
## 5. Filter Alignment (`listWorkflowsInternal`)
- Update the status filter to handle the new field mapping.
- If user filters by `status: 'CLOSED'`, the query will target `workflowState: 'CLOSED'`.
- If user filters by `status: 'APPROVED'`, the query will target `status: 'APPROVED'`.