2.3 KiB
2.3 KiB
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
statusEnum: RemoveCLOSEDandCANCELLED. - Add
workflowState:- Type:
String - Enum:
['DRAFT', 'OPEN', 'CLOSED'] - Default:
'DRAFT' - Index:
true
- Type:
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
statusasIN_PROGRESSor set toAPPROVEDif final. - When rejected: Set
statustoREJECTED. - Crucial: The
workflowStateremainsOPENduring these actions.
D. Finalization (ConclusionController.finalizeConclusion)
- Current Behavior: Sets
status = 'CLOSED'. - New Behavior:
- Sets
workflowState = 'CLOSED'. - Does NOT change
status. Thestatuswill remainAPPROVEDorREJECTED. - Sets
closureDate = new Date().
- Sets
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. OPENcategory will now include all requests whereworkflowState == 'OPEN'.CLOSEDcategory will now include all requests whereworkflowState == '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 ofstatus: 'CLOSED'.
5. Filter Alignment (listWorkflowsInternal)
- Update the status filter to handle the new field mapping.
- If user filters by
status: 'CLOSED', the query will targetworkflowState: 'CLOSED'. - If user filters by
status: 'APPROVED', the query will targetstatus: 'APPROVED'.