diff --git a/src/card/controllers/cards.controller.ts b/src/card/controllers/cards.controller.ts index dd26753..e61167d 100644 --- a/src/card/controllers/cards.controller.ts +++ b/src/card/controllers/cards.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, HttpCode, HttpStatus, Post, UseGuards } from '@nestjs/common'; +import { Body, Controller, Get, HttpCode, HttpStatus, Param, Post, UseGuards } from '@nestjs/common'; import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger'; import { Roles } from '~/auth/enums'; import { IJwtPayload } from '~/auth/interfaces'; @@ -34,6 +34,15 @@ export class CardsController { return ResponseFactory.data(cards.map((card) => new ChildCardResponseDto(card))); } + @Get('child-cards/:cardid/embossing-details') + @UseGuards(RolesGuard) + @AllowedRoles(Roles.GUARDIAN) + @ApiDataResponse(CardEmbossingDetailsResponseDto) + async getChildCardEmbossingDetails(@Param('cardid') cardId: string, @AuthenticatedUser() { sub }: IJwtPayload) { + const res = await this.cardService.getChildCardEmbossingInformation(cardId, sub); + return ResponseFactory.data(res); + } + @Get('current') @ApiDataResponse(CardResponseDto) async getCurrentCard(@AuthenticatedUser() { sub }: IJwtPayload) { diff --git a/src/card/services/card.service.ts b/src/card/services/card.service.ts index bd5e8ed..edc9288 100644 --- a/src/card/services/card.service.ts +++ b/src/card/services/card.service.ts @@ -114,6 +114,14 @@ export class CardService { return this.neoleapService.getEmbossingInformation(card); } + async getChildCardEmbossingInformation(cardId: string, guardianId: string) { + const card = await this.getCardById(cardId); + if (card.parentId !== guardianId) { + throw new BadRequestException('CARD.DOES_NOT_BELONG_TO_GUARDIAN'); + } + return this.neoleapService.getEmbossingInformation(card); + } + async updateCardLimit(cardId: string, newLimit: number) { const { affected } = await this.cardRepository.updateCardLimit(cardId, newLimit); diff --git a/src/i18n/ar/app.json b/src/i18n/ar/app.json index ce28fcb..5030ff1 100644 --- a/src/i18n/ar/app.json +++ b/src/i18n/ar/app.json @@ -100,8 +100,9 @@ }, "OTP": { "INVALID_OTP": "رمز التحقق الذي أدخلته غير صالح. يرجى المحاولة مرة أخرى." - }, - "CARD": { - "INSUFFICIENT_BALANCE": "البطاقة لا تحتوي على رصيد كافٍ لإكمال هذا التحويل." + }, + "CARD": { + "INSUFFICIENT_BALANCE": "البطاقة لا تحتوي على رصيد كافٍ لإكمال هذا التحويل.", + "DOES_NOT_BELONG_TO_GUARDIAN": "البطاقة لا تنتمي إلى ولي الأمر." } } diff --git a/src/i18n/en/app.json b/src/i18n/en/app.json index 06654e5..a04edd2 100644 --- a/src/i18n/en/app.json +++ b/src/i18n/en/app.json @@ -101,6 +101,7 @@ "INVALID_OTP": "The OTP you entered is invalid. Please try again." }, "CARD": { - "INSUFFICIENT_BALANCE": "The card does not have sufficient balance to complete this transfer." + "INSUFFICIENT_BALANCE": "The card does not have sufficient balance to complete this transfer.", + "DOES_NOT_BELONG_TO_GUARDIAN": "The card does not belong to the guardian." } }