Treasury & Bank Transfer Management System — سامانه مدیریت خزانه‌داری و حواله‌های بانکی

Require explicit CHECKER or authorized treasury admin roles for approval, queue, bank dispatch and polling

davoodmehraban89 committed Oct 23, 2026 at 11:12 UTC 95f2925fdc52c63489dfb580f92c1114e6895e1e
1 file changed +4
src/platform/application/treasury-service.ts
+4
@@ -152,6 +152,7 @@ export class TreasuryService{
152 }
153
154 approvePayment(id:string){
155 + if(this.actor.role!=='CHECKER')throw new Error('checker role required');
156 const payment=this.getPayment(id);
157 if(!canApprove({actorId:this.actor.userId,makerId:payment.makerId},payment.version)) throw new Error('maker cannot approve own payment');
158 if(payment.state!=='PENDING_APPROVAL') throw new Error('payment not pending approval');
@@ -191,12 +192,14 @@ export class TreasuryService{
192 }
193
194 queuePayment(id:string){
195 + if(this.actor.role!=='CHECKER'&&this.actor.role!=='TREASURY_ADMIN')throw new Error('checker or admin role required');
196 const payment=this.getPayment(id);
197 if(payment.state!=='APPROVED'||payment.approvedVersion!==payment.version) throw new Error('payment not eligible for queue');
198 return this.changeState(id,transitionPayment(payment.state,'QUEUE'),'PAYMENT_QUEUED',payment);
199 }
200
201 async dispatchPayment(id:string,adapter:BankAdapter){
202 + if(this.actor.role!=='CHECKER'&&this.actor.role!=='TREASURY_ADMIN')throw new Error('checker or admin role required');
203 // Reserve once in durable storage BEFORE any external bank request.
204 // The QUEUED -> DISPATCHING transition is atomic across SQLite writers.
205 // A crash at any point leaves DISPATCHING/UNKNOWN for manual reconciliation;
@@ -245,6 +248,7 @@ export class TreasuryService{
248 }
249
250 async pollPaymentStatus(id:string,adapter:BankAdapter){
251 + if(this.actor.role!=='CHECKER'&&this.actor.role!=='TREASURY_ADMIN')throw new Error('checker or admin role required');
252 const payment=this.getPayment(id);
253 if(payment.state!=='SUBMITTED'||!payment.bankReference) throw new Error('payment not eligible for polling');
254 const outcome=await adapter.poll(payment.bankReference);