mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 00:24:54 +00:00
fix: fix transfer to child bug
This commit is contained in:
@ -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 })
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user