Multi-Level Approval System
Dokumentasi lengkap sistem approval multi-level di MStore Backend dengan support delegation, auto-approve SLA, dan role-based workflow.π― Overview
Sistem approval MStore dirancang dengan prinsip:- β Multi-Level: Support approval bertingkat (L1, L2, L3, dst)
- β Role-Based: Approval berdasarkan role (MAKER, CHECKER, APPROVER)
- β Delegation: Temporary delegation dengan time range
- β Auto-Approve SLA: Automatic approval jika melewati SLA
- β Flexible Rules: Approval rules berdasarkan doc type & amount range
- β Audit Trail: Complete log untuk setiap action
- β Merchant-Scoped: Isolasi approval per merchant/branch
ποΈ Architecture
π Data Model
1. Roles (Global RBAC)
2. Approvers (User-Role Mapping)
- role_order: Urutan approver dalam role yang sama (untuk approval_mode=βallβ)
- Delegation: Temporary delegation ke user lain
- Scope: Merchant & branch level isolation
3. Approval Flows (Rules Definition)
- all: Semua approver di level harus approve
- any: Salah satu approver di level cukup approve
4. Approval Requests
5. Approval Logs (Audit Trail)
π Approval Flow
State Machine
Example Flow: Inventory Transfer
Scenario: Transfer senilai Rp 5.000.000 memerlukan 2 level approval Setup:π» Implementation
1. Create Approval Request
2. Process Approval Action
3. Auto-Approve Scheduler
4. Delegation Handling
π‘ API Endpoints
1. Create Approval Request
2. Get Pending Approvals (for Approver)
3. Process Approval Action
4. Get Approval History
π§ͺ Testing Scenarios
Scenario 1: Two-Level Approval
Scenario 2: Rejection at Level 1
Scenario 3: Auto-Approve SLA
π‘ Best Practices
DO β
- Define clear approval flows per document type & amount range
- Use role-based approvers untuk flexibility
- Implement delegation untuk coverage saat approver unavailable
- Set reasonable SLA untuk auto-approve
- Log semua actions dengan IP & user agent
- Notify approvers via email/in-app notification
- Implement approval dashboard untuk monitoring
- Use transaction untuk atomic operations
DONβT β
- Jangan hardcode approver user IDs
- Jangan skip audit logging
- Jangan allow approval tanpa authentication
- Jangan ignore SLA monitoring
- Jangan allow self-approval (requester = approver)
- Jangan skip validation untuk approval permission
π Troubleshooting
Problem: Approval Stuck
Symptoms: Request tidak bergerak meski sudah approve Solution:π Related Documentation
Inventory Flow
Approval untuk inventory transfers
Transaction Flow
Approval untuk void transactions
RBAC System
Role-based access control
Need Help? Contact backend team atau check GitHub Issues