fix: fix transfer to child bug

This commit is contained in:
Abdalhameed Ahmad
2025-09-16 21:01:32 +03:00
parent f1484e125b
commit 454ded627f
2 changed files with 21 additions and 3 deletions

View File

@ -22,10 +22,28 @@ export class Account {
@Column('varchar', { length: 255, nullable: false, name: 'currency' }) @Column('varchar', { length: 255, nullable: false, name: 'currency' })
currency!: string; currency!: string;
@Column('decimal', { precision: 10, scale: 2, default: 0.0, name: 'balance' }) @Column('decimal', {
precision: 10,
scale: 2,
default: 0.0,
name: 'balance',
transformer: {
to: (value: number) => value,
from: (value: string) => parseFloat(value),
},
})
balance!: number; balance!: number;
@Column('decimal', { precision: 10, scale: 2, default: 0.0, name: 'reserved_balance' }) @Column('decimal', {
precision: 10,
scale: 2,
default: 0.0,
name: 'reserved_balance',
transformer: {
to: (value: number) => value,
from: (value: string) => parseFloat(value),
},
})
reservedBalance!: number; reservedBalance!: number;
@OneToMany(() => Card, (card) => card.account, { cascade: true }) @OneToMany(() => Card, (card) => card.account, { cascade: true })

View File

@ -65,7 +65,7 @@ export class AccountService {
increaseReservedBalance(account: Account, amount: number) { increaseReservedBalance(account: Account, amount: number) {
if (account.balance < account.reservedBalance + amount) { if (account.balance < account.reservedBalance + amount) {
throw new UnprocessableEntityException('ACCOUNT.INSUFFICIENT_BALANCE'); throw new UnprocessableEntityException('CARD.INSUFFICIENT_BALANCE');
} }
return this.accountRepository.increaseReservedBalance(account.id, amount); return this.accountRepository.increaseReservedBalance(account.id, amount);
} }