mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 21:59:40 +00:00
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { CreateApplicationResponse } from '~/common/modules/neoleap/dtos/response';
|
|
import { Account } from '../entities/account.entity';
|
|
|
|
@Injectable()
|
|
export class AccountRepository {
|
|
constructor(@InjectRepository(Account) private readonly accountRepository: Repository<Account>) {}
|
|
|
|
createAccount(data: CreateApplicationResponse): Promise<Account> {
|
|
return this.accountRepository.save(
|
|
this.accountRepository.create({
|
|
accountReference: data.accountId,
|
|
accountNumber: data.accountNumber,
|
|
iban: data.iBan,
|
|
balance: 0,
|
|
currency: '682',
|
|
}),
|
|
);
|
|
}
|
|
|
|
getAccountByReferenceNumber(accountReference: string): Promise<Account | null> {
|
|
return this.accountRepository.findOne({
|
|
where: { accountReference },
|
|
relations: ['cards'],
|
|
});
|
|
}
|
|
|
|
getAccountByAccountNumber(accountNumber: string): Promise<Account | null> {
|
|
return this.accountRepository.findOne({
|
|
where: { accountNumber },
|
|
relations: ['cards'],
|
|
});
|
|
}
|
|
|
|
topUpAccountBalance(accountReference: string, amount: number) {
|
|
return this.accountRepository.increment({ accountReference }, 'balance', amount);
|
|
}
|
|
|
|
decreaseAccountBalance(accountReference: string, amount: number) {
|
|
return this.accountRepository.decrement({ accountReference }, 'balance', amount);
|
|
}
|
|
}
|