mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +00:00
feat: add transaction, card , and account entities
This commit is contained in:
37
src/card/services/card.service.ts
Normal file
37
src/card/services/card.service.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { Transactional } from 'typeorm-transactional';
|
||||
import { CreateApplicationResponse } from '~/common/modules/neoleap/dtos/response';
|
||||
import { Card } from '../entities';
|
||||
import { CardRepository } from '../repositories';
|
||||
import { AccountService } from './account.service';
|
||||
|
||||
@Injectable()
|
||||
export class CardService {
|
||||
constructor(private readonly cardRepository: CardRepository, private readonly accountService: AccountService) {}
|
||||
|
||||
@Transactional()
|
||||
async createCard(customerId: string, cardData: CreateApplicationResponse): Promise<Card> {
|
||||
const account = await this.accountService.createAccount(cardData.accountId);
|
||||
return this.cardRepository.createCard(customerId, account.id, cardData);
|
||||
}
|
||||
|
||||
async getCardById(id: string): Promise<Card> {
|
||||
const card = await this.cardRepository.getCardById(id);
|
||||
|
||||
if (!card) {
|
||||
throw new BadRequestException('CARD.NOT_FOUND');
|
||||
}
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
async getCardByReferenceNumber(referenceNumber: string): Promise<Card> {
|
||||
const card = await this.cardRepository.getCardByReferenceNumber(referenceNumber);
|
||||
|
||||
if (!card) {
|
||||
throw new BadRequestException('CARD.NOT_FOUND');
|
||||
}
|
||||
|
||||
return card;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user