mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 00:24:54 +00:00
feat: get card by child id
This commit is contained in:
@ -34,6 +34,15 @@ export class CardsController {
|
|||||||
return ResponseFactory.data(cards.map((card) => new ChildCardResponseDto(card)));
|
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')
|
@Get('child-cards/:cardid/embossing-details')
|
||||||
@UseGuards(RolesGuard)
|
@UseGuards(RolesGuard)
|
||||||
@AllowedRoles(Roles.GUARDIAN)
|
@AllowedRoles(Roles.GUARDIAN)
|
||||||
|
|||||||
@ -45,6 +45,13 @@ export class CardRepository {
|
|||||||
return this.cardRepository.findOne({ where: { id }, relations: ['account'] });
|
return this.cardRepository.findOne({ where: { id }, relations: ['account'] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findCardByChildId(guardianId: string, childId: string): Promise<Card | null> {
|
||||||
|
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<Card | null> {
|
getCardByReferenceNumber(referenceNumber: string): Promise<Card | null> {
|
||||||
return this.cardRepository.findOne({ where: { cardReference: referenceNumber }, relations: ['account'] });
|
return this.cardRepository.findOne({ where: { cardReference: referenceNumber }, relations: ['account'] });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,6 +63,15 @@ export class CardService {
|
|||||||
|
|
||||||
return this.getCardById(createdCard.id);
|
return this.getCardById(createdCard.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getCardByChildId(guardianId: string, childId: string): Promise<Card> {
|
||||||
|
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<Card> {
|
async getCardById(id: string): Promise<Card> {
|
||||||
const card = await this.cardRepository.getCardById(id);
|
const card = await this.cardRepository.getCardById(id);
|
||||||
|
|
||||||
|
|||||||
@ -103,6 +103,7 @@
|
|||||||
},
|
},
|
||||||
"CARD": {
|
"CARD": {
|
||||||
"INSUFFICIENT_BALANCE": "البطاقة لا تحتوي على رصيد كافٍ لإكمال هذا التحويل.",
|
"INSUFFICIENT_BALANCE": "البطاقة لا تحتوي على رصيد كافٍ لإكمال هذا التحويل.",
|
||||||
"DOES_NOT_BELONG_TO_GUARDIAN": "البطاقة لا تنتمي إلى ولي الأمر."
|
"DOES_NOT_BELONG_TO_GUARDIAN": "البطاقة لا تنتمي إلى ولي الأمر.",
|
||||||
|
"NOT_FOUND": "لم يتم العثور على البطاقة."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,6 +102,7 @@
|
|||||||
},
|
},
|
||||||
"CARD": {
|
"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."
|
"DOES_NOT_BELONG_TO_GUARDIAN": "The card does not belong to the guardian.",
|
||||||
|
"NOT_FOUND": "The card was not found."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user