feat(backend): add admin workflow engine for multi-step approval flows#1156
Merged
Conversation
Implements a standardised workflow engine for high-risk admin actions that require approval before execution (issue Devsol-01#1119). ## Data Model - AdminWorkflow entity with full state machine: PENDING_APPROVAL -> APPROVED -> EXECUTED -> REJECTED PENDING_APPROVAL -> CANCELED | TIMED_OUT - Idempotency key support to prevent duplicate workflow creation - Before/after state snapshots stored per workflow for audit diffs - Per-workflow configurable requiredApproverRole and timeout - Migration: 1803000000000-CreateAdminWorkflowsTable.ts ## Service Layer - WorkflowService: create (idempotent), approve, reject, cancel, markExecuted (idempotent), recordExecutionFailure, list/find, and @Cron-based auto-expiry every 5 minutes - WorkflowAuditService: emits AuditLog entries on every state transition with before/after diffs; non-fatal (never crashes caller) - EmergencyWithdrawalWorkflowService: bridges the engine to the existing savings withdrawal processing flow ## API Endpoints - POST /v1/admin/workflows - initiate workflow - GET /v1/admin/workflows - list with filters - GET /v1/admin/workflows/:id - get detail - PATCH /v1/admin/workflows/:id/approve - approve (role-gated) - PATCH /v1/admin/workflows/:id/reject - reject (role-gated) - PATCH /v1/admin/workflows/:id/cancel - cancel ## Migrated High-Risk Endpoint (emergency withdrawal) - POST /v1/admin/withdrawals/:id/emergency-workflow (initiate, ADMIN+) - POST /v1/admin/withdrawals/workflow/:id/execute (execute, SUPER_ADMIN) ## Guards - WorkflowStepGuard: dynamic per-workflow role check based on requiredApproverRole field, applied on approve/reject endpoints ## Tests (30/30 passing) - workflow.service.spec.ts (23 tests): idempotent create, state machine transitions, role gating, self-approval prevention, timeout expiry cron, idempotent execution - workflow-audit.service.spec.ts (7 tests): all transition types, before/after diff accuracy, non-fatal failure handling
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
@abrak01 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a standardised workflow engine for high-risk admin actions that require approval before execution (issue #1119).
Data Model
Service Layer
API Endpoints
Migrated High-Risk Endpoint (emergency withdrawal)
Guards
Tests (30/30 passing)
closes #1119