-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Labels
Stellar WaveIssues in the Stellar wave programIssues in the Stellar wave programbackendgood first issueGood for newcomersGood for newcomersnestjs
Description
Description
Build a robust workflow engine for handling asset transfers between users, departments, and locations with approval chains, notifications, and complete audit trails.
Requirements
Transfer Entity:
Transfer {
id: UUID (primary key)
transferType: enum (USER, DEPARTMENT, LOCATION, COMPLETE)
assets: ManyToMany -> Asset
fromUser: ManyToOne -> User (nullable)
toUser: ManyToOne -> User (nullable)
fromDepartment: ManyToOne -> Department (nullable)
toDepartment: ManyToOne -> Department (nullable)
fromLocation: ManyToOne -> Location (nullable)
toLocation: ManyToOne -> Location (nullable)
status: enum (PENDING, APPROVED, REJECTED, COMPLETED, CANCELLED)
requestedBy: ManyToOne -> User
approvedBy: ManyToOne -> User (nullable)
rejectedBy: ManyToOne -> User (nullable)
reason: text (required)
notes: text (optional)
approvalRequired: boolean (default: false)
rejectionReason: text (nullable)
scheduledDate: timestamp (nullable)
completedAt: timestamp (nullable)
createdAt: timestamp
updatedAt: timestamp
}TransferApprovalRule Entity:
TransferApprovalRule {
id: UUID (primary key)
name: string (required)
description: text (optional)
conditions: jsonb (e.g., { minValue: 1000, categories: [...] })
approverRole: ManyToOne -> Role
approverUser: ManyToOne -> User (nullable)
isActive: boolean (default: true)
priority: integer (for multiple rules)
createdAt: timestamp
updatedAt: timestamp
}API Endpoints:
POST /api/v1/transfers- Create transfer requestGET /api/v1/transfers- List transfers (with filters)GET /api/v1/transfers/:id- Get transfer detailsPUT /api/v1/transfers/:id/approve- Approve transferPUT /api/v1/transfers/:id/reject- Reject transferDELETE /api/v1/transfers/:id- Cancel pending transferPOST /api/v1/transfers/:id/execute- Manually execute approved transferPOST /api/v1/transfers/:id/undo- Undo completed transfer (within time limit)GET /api/v1/transfers/pending-approval- Get transfers pending my approvalPOST /api/v1/transfers/approval-rules- Create approval ruleGET /api/v1/transfers/approval-rules- List approval rulesPUT /api/v1/transfers/approval-rules/:id- Update approval ruleDELETE /api/v1/transfers/approval-rules/:id- Delete approval rule
Business Logic:
- Evaluate approval rules when transfer is created
- Auto-approve transfers that don't meet approval criteria
- Send notifications to approvers when approval required
- Prevent transfer of RETIRED assets
- Validate that assets are available for transfer (not in another pending transfer)
- Execute scheduled transfers at specified date/time (cron job)
- Create asset history entries for all transfers
- Update asset assignments atomically (transaction)
- Allow undo within configurable time window (default: 24 hours)
- Lock assets during transfer to prevent concurrent modifications
Approval Rule Matching:
// Example conditions
{
minValue: 5000, // Requires approval if total asset value > 5000
maxValue: null,
categories: ['Computer', 'Vehicle'], // Requires approval for these categories
departments: ['IT', 'Finance'], // Requires approval for these departments
requiresAllConditions: false // OR logic vs AND logic
}Validation Rules:
- At least one asset must be selected
- Transfer reason: 10-500 characters
- Cannot transfer to same user/department/location
- Assets must exist and not be deleted
- Destination user/department/location must exist
- Scheduled date must be in future
- Cannot approve/reject your own transfer request
Technical Specifications
- Use database transactions for atomic transfers
- Implement pessimistic locking to prevent race conditions
- Create background job queue for scheduled transfers (Bull/BullMQ)
- Implement event emitters for notifications
- Use Redis for transfer locks and rate limiting
- Create indexes on status, requestedBy, scheduledDate
- Implement idempotent transfer execution
- Add retry mechanism for failed transfers
Metadata
Metadata
Assignees
Labels
Stellar WaveIssues in the Stellar wave programIssues in the Stellar wave programbackendgood first issueGood for newcomersGood for newcomersnestjs