feat: transfer to parent

This commit is contained in:
Abdalhameed Ahmad
2025-09-07 20:23:11 +03:00
parent 9b0e1791da
commit d768da70f2
6 changed files with 45 additions and 4 deletions

View File

@ -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));
}
} }

View File

@ -0,0 +1,10 @@
import { ApiProperty } from '@nestjs/swagger';
export class AccountIbanResponseDto {
@ApiProperty({ example: 'DE89370400440532013000' })
iban!: string;
constructor(iban: string) {
this.iban = iban;
}
}

View File

@ -1 +1,2 @@
export * from './account-iban.response.dto';
export * from './card.response.dto'; export * from './card.response.dto';

View File

@ -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);
} }

View File

@ -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);
/** /**

View File

@ -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);