mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 00:24:54 +00:00
feat: transfer to parent
This commit is contained in:
@ -1,12 +1,13 @@
|
|||||||
import { Controller, Get, Post, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Post, UseGuards } from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { Roles } from '~/auth/enums';
|
||||||
import { IJwtPayload } from '~/auth/interfaces';
|
import { IJwtPayload } from '~/auth/interfaces';
|
||||||
import { AuthenticatedUser } from '~/common/decorators';
|
import { AllowedRoles, AuthenticatedUser } from '~/common/decorators';
|
||||||
import { AccessTokenGuard } from '~/common/guards';
|
import { AccessTokenGuard, RolesGuard } from '~/common/guards';
|
||||||
import { CardEmbossingDetailsResponseDto } from '~/common/modules/neoleap/dtos/response';
|
import { CardEmbossingDetailsResponseDto } from '~/common/modules/neoleap/dtos/response';
|
||||||
import { ApiDataResponse } from '~/core/decorators';
|
import { ApiDataResponse } from '~/core/decorators';
|
||||||
import { ResponseFactory } from '~/core/utils';
|
import { ResponseFactory } from '~/core/utils';
|
||||||
import { CardResponseDto } from '../dtos/responses';
|
import { AccountIbanResponseDto, CardResponseDto } from '../dtos/responses';
|
||||||
import { CardService } from '../services';
|
import { CardService } from '../services';
|
||||||
|
|
||||||
@Controller('cards')
|
@Controller('cards')
|
||||||
@ -36,4 +37,13 @@ export class CardsController {
|
|||||||
const res = await this.cardService.getEmbossingInformation(sub);
|
const res = await this.cardService.getEmbossingInformation(sub);
|
||||||
return ResponseFactory.data(res);
|
return ResponseFactory.data(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('iban')
|
||||||
|
@UseGuards(RolesGuard)
|
||||||
|
@AllowedRoles(Roles.GUARDIAN)
|
||||||
|
@ApiDataResponse(AccountIbanResponseDto)
|
||||||
|
async getCardIban(@AuthenticatedUser() { sub }: IJwtPayload) {
|
||||||
|
const iban = await this.cardService.getIbanInformation(sub);
|
||||||
|
return ResponseFactory.data(new AccountIbanResponseDto(iban));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/card/dtos/responses/account-iban.response.dto.ts
Normal file
10
src/card/dtos/responses/account-iban.response.dto.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
export class AccountIbanResponseDto {
|
||||||
|
@ApiProperty({ example: 'DE89370400440532013000' })
|
||||||
|
iban!: string;
|
||||||
|
|
||||||
|
constructor(iban: string) {
|
||||||
|
this.iban = iban;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1 +1,2 @@
|
|||||||
|
export * from './account-iban.response.dto';
|
||||||
export * from './card.response.dto';
|
export * from './card.response.dto';
|
||||||
|
|||||||
@ -34,6 +34,13 @@ export class AccountRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAccountByCustomerId(customerId: string): Promise<Account | null> {
|
||||||
|
return this.accountRepository.findOne({
|
||||||
|
where: { cards: { customerId } },
|
||||||
|
relations: ['cards'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
topUpAccountBalance(accountReference: string, amount: number) {
|
topUpAccountBalance(accountReference: string, amount: number) {
|
||||||
return this.accountRepository.increment({ accountReference }, 'balance', amount);
|
return this.accountRepository.increment({ accountReference }, 'balance', amount);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,10 +27,18 @@ export class AccountService {
|
|||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
async creditAccountBalance(accountReference: string, amount: number) {
|
creditAccountBalance(accountReference: string, amount: number) {
|
||||||
return this.accountRepository.topUpAccountBalance(accountReference, amount);
|
return this.accountRepository.topUpAccountBalance(accountReference, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getAccountByCustomerId(customerId: string): Promise<Account> {
|
||||||
|
const account = await this.accountRepository.getAccountByCustomerId(customerId);
|
||||||
|
if (!account) {
|
||||||
|
throw new UnprocessableEntityException('ACCOUNT.NOT_FOUND');
|
||||||
|
}
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
async decreaseAccountBalance(accountReference: string, amount: number) {
|
async decreaseAccountBalance(accountReference: string, amount: number) {
|
||||||
const account = await this.getAccountByReferenceNumber(accountReference);
|
const account = await this.getAccountByReferenceNumber(accountReference);
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -111,6 +111,11 @@ export class CardService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getIbanInformation(customerId: string) {
|
||||||
|
const account = await this.accountService.getAccountByCustomerId(customerId);
|
||||||
|
return account.iban;
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional()
|
@Transactional()
|
||||||
async transferToChild(juniorId: string, amount: number) {
|
async transferToChild(juniorId: string, amount: number) {
|
||||||
const card = await this.getCardByCustomerId(juniorId);
|
const card = await this.getCardByCustomerId(juniorId);
|
||||||
|
|||||||
Reference in New Issue
Block a user