Treasury & Bank Transfer Management System — سامانه مدیریت خزانهداری و حوالههای بانکی
Make financial draft and master-data creation audit atomic in existing store transaction
davoodmehraban89 committed
Oct 23, 2026 at 10:54 UTC
f75e0b42a86a866f795d69578d9d0bd1a9b95ac0
1 file changed
+15
-15
src/platform/application/treasury-service.ts
+15
-15
@@ -8,7 +8,7 @@ import {BankDispatchRegistry} from '../../domain/bank-adapter';
8
import {validateIranianIban} from '../../domain/iran/iban';
9
import {evaluatePaymentGuard} from '../../domain/payments/payment-guard';
10
import type {TreasuryStore} from './store';
11
-import type {ActorContext,LocalAccount,LocalAudit,LocalBeneficiary,LocalPayment} from './types';
11
+import type {ActorContext,LocalAccount,LocalAudit,LocalBeneficiary,LocalPayment,LocalStoreData} from './types';
12
13
export class TreasuryService{
14
constructor(private readonly store:TreasuryStore,private readonly actor:ActorContext){}
@@ -17,20 +17,20 @@ export class TreasuryService{
17
return rows.filter(x=>x.tenantId===this.actor.tenantId);
18
}
19
20
- private appendAudit(action:string,entity:string){
21
- this.store.update(d=>{
22
- d.audit.push({
23
- tenantId:this.actor.tenantId,
24
- seq:d.audit.length+1,
25
- actor:this.actor.userId,
26
- action,
27
- entity,
28
- at:Date.now()
29
- });
30
- return d;
20
+ /** Append audit into the same store transaction as its financial mutation. */
21
+ private appendAuditTo(d:LocalStoreData,action:string,entity:string){
22
+ d.audit.push({
23
+ tenantId:this.actor.tenantId,
24
+ seq:d.audit.length+1,
25
+ actor:this.actor.userId,
26
+ action,entity,at:Date.now()
27
});
28
}
29
30
+ private appendAudit(action:string,entity:string){
31
+ this.store.update(d=>{this.appendAuditTo(d,action,entity);return d;});
32
+ }
33
+
34
listAccounts(){return this.own(this.store.snapshot().accounts)}
35
listBeneficiaries(){return this.own(this.store.snapshot().beneficiaries)}
36
listPayments(){return this.own(this.store.snapshot().payments)}
@@ -56,9 +56,9 @@ export class TreasuryService{
56
this.store.update(d=>{
57
if(d.accounts.some(x=>x.tenantId===account.tenantId&&x.id===account.id)) throw new Error('duplicate account');
58
d.accounts.push(account);
59
+ this.appendAuditTo(d,'ACCOUNT_CREATED',account.id);
60
return d;
61
});
61
- this.appendAudit('ACCOUNT_CREATED',account.id);
62
return account;
63
}
64
@@ -74,9 +74,9 @@ export class TreasuryService{
74
this.store.update(d=>{
75
if(d.beneficiaries.some(x=>x.tenantId===beneficiary.tenantId&&x.id===beneficiary.id)) throw new Error('duplicate beneficiary');
76
d.beneficiaries.push(beneficiary);
77
+ this.appendAuditTo(d,'BENEFICIARY_CREATED',beneficiary.id);
78
return d;
79
});
79
- this.appendAudit('BENEFICIARY_CREATED',beneficiary.id);
80
return beneficiary;
81
}
82
@@ -100,9 +100,9 @@ export class TreasuryService{
100
this.store.update(d=>{
101
if(d.payments.some(x=>x.tenantId===payment.tenantId&&(x.id===payment.id||x.clientReference===payment.clientReference))) throw new Error('duplicate payment reference');
102
d.payments.push(payment);
103
+ this.appendAuditTo(d,'PAYMENT_CREATED',payment.id);
104
return d;
105
});
105
- this.appendAudit('PAYMENT_CREATED',payment.id);
106
return payment;
107
}
108