From df4d2e3c1f97d953b2e08603fd74e708ea3f87b7 Mon Sep 17 00:00:00 2001 From: Abdalhameed Ahmad Date: Mon, 15 Sep 2025 08:47:56 +0300 Subject: [PATCH] feat: get card by child id --- src/card/controllers/cards.controller.ts | 9 +++++++++ src/card/repositories/card.repository.ts | 7 +++++++ src/card/services/card.service.ts | 9 +++++++++ src/i18n/ar/app.json | 3 ++- src/i18n/en/app.json | 3 ++- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/card/controllers/cards.controller.ts b/src/card/controllers/cards.controller.ts index e61167d..4b129fc 100644 --- a/src/card/controllers/cards.controller.ts +++ b/src/card/controllers/cards.controller.ts @@ -34,6 +34,15 @@ export class CardsController { return ResponseFactory.data(cards.map((card) => new ChildCardResponseDto(card))); } + @Get('child-cards/:childid') + @UseGuards(RolesGuard) + @AllowedRoles(Roles.GUARDIAN) + @ApiDataResponse(ChildCardResponseDto) + async getChildCardById(@Param('childid') childId: string, @AuthenticatedUser() { sub }: IJwtPayload) { + const card = await this.cardService.getCardByChildId(sub, childId); + return ResponseFactory.data(new ChildCardResponseDto(card)); + } + @Get('child-cards/:cardid/embossing-details') @UseGuards(RolesGuard) @AllowedRoles(Roles.GUARDIAN) diff --git a/src/card/repositories/card.repository.ts b/src/card/repositories/card.repository.ts index ee121a5..18a161f 100644 --- a/src/card/repositories/card.repository.ts +++ b/src/card/repositories/card.repository.ts @@ -45,6 +45,13 @@ export class CardRepository { return this.cardRepository.findOne({ where: { id }, relations: ['account'] }); } + findCardByChildId(guardianId: string, childId: string): Promise { + return this.cardRepository.findOne({ + where: { parentId: guardianId, customerId: childId, customerType: CustomerType.CHILD }, + relations: ['account', 'customer', 'customer.user', 'customer.user.profilePicture', 'customer.junior'], + }); + } + getCardByReferenceNumber(referenceNumber: string): Promise { return this.cardRepository.findOne({ where: { cardReference: referenceNumber }, relations: ['account'] }); } diff --git a/src/card/services/card.service.ts b/src/card/services/card.service.ts index edc9288..9235aab 100644 --- a/src/card/services/card.service.ts +++ b/src/card/services/card.service.ts @@ -63,6 +63,15 @@ export class CardService { return this.getCardById(createdCard.id); } + + async getCardByChildId(guardianId: string, childId: string): Promise { + const card = await this.cardRepository.findCardByChildId(guardianId, childId); + if (!card) { + throw new BadRequestException('CARD.NOT_FOUND'); + } + await this.prepareJuniorImages([card]); + return card; + } async getCardById(id: string): Promise { const card = await this.cardRepository.getCardById(id); diff --git a/src/i18n/ar/app.json b/src/i18n/ar/app.json index 5030ff1..24735cb 100644 --- a/src/i18n/ar/app.json +++ b/src/i18n/ar/app.json @@ -103,6 +103,7 @@ }, "CARD": { "INSUFFICIENT_BALANCE": "البطاقة لا تحتوي على رصيد كافٍ لإكمال هذا التحويل.", - "DOES_NOT_BELONG_TO_GUARDIAN": "البطاقة لا تنتمي إلى ولي الأمر." + "DOES_NOT_BELONG_TO_GUARDIAN": "البطاقة لا تنتمي إلى ولي الأمر.", + "NOT_FOUND": "لم يتم العثور على البطاقة." } } diff --git a/src/i18n/en/app.json b/src/i18n/en/app.json index a04edd2..48f2bd7 100644 --- a/src/i18n/en/app.json +++ b/src/i18n/en/app.json @@ -102,6 +102,7 @@ }, "CARD": { "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." + "DOES_NOT_BELONG_TO_GUARDIAN": "The card does not belong to the guardian.", + "NOT_FOUND": "The card was not found." } }