Skip to content

feat(backend): add admin workflow engine for multi-step approval flows#1156

Merged
Devsol-01 merged 2 commits into
Devsol-01:mainfrom
abrak01:feat/admin-workflow-engine
Jun 30, 2026
Merged

feat(backend): add admin workflow engine for multi-step approval flows#1156
Devsol-01 merged 2 commits into
Devsol-01:mainfrom
abrak01:feat/admin-workflow-engine

Conversation

@abrak01

@abrak01 abrak01 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Implements a standardised workflow engine for high-risk admin actions that require approval before execution (issue #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

closes #1119

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
@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
nestera Skipped Skipped Jun 30, 2026 3:20am

@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@Devsol-01 Devsol-01 merged commit 403c2c9 into Devsol-01:main Jun 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] -- Add Admin Workflow Engine for Multi-Step Actions (Approval + Audit + Timeout)

2 participants