mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 13:49:40 +00:00
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { CreateApplicationResponse } from '~/common/modules/neoleap/dtos/response';
|
|
import { Card } from '../entities';
|
|
import { CardColors, CardIssuers, CardScheme, CardStatus, CardStatusDescription, CustomerType } from '../enums';
|
|
|
|
@Injectable()
|
|
export class CardRepository {
|
|
constructor(@InjectRepository(Card) private readonly cardRepository: Repository<Card>) {}
|
|
|
|
createCard(
|
|
customerId: string,
|
|
accountId: string,
|
|
card: CreateApplicationResponse,
|
|
cardColor?: CardColors,
|
|
): Promise<Card> {
|
|
return this.cardRepository.save(
|
|
this.cardRepository.create({
|
|
customerId: customerId,
|
|
expiry: card.expiryDate,
|
|
cardReference: card.cardId,
|
|
customerType: CustomerType.PARENT,
|
|
firstSixDigits: card.firstSixDigits,
|
|
lastFourDigits: card.lastFourDigits,
|
|
color: cardColor ? cardColor : CardColors.DEEP_MAGENTA,
|
|
scheme: CardScheme.VISA,
|
|
issuer: CardIssuers.NEOLEAP,
|
|
accountId: accountId,
|
|
vpan: card.vpan,
|
|
}),
|
|
);
|
|
}
|
|
|
|
getCardById(id: string): Promise<Card | null> {
|
|
return this.cardRepository.findOne({ where: { id }, relations: ['account'] });
|
|
}
|
|
|
|
getCardByReferenceNumber(referenceNumber: string): Promise<Card | null> {
|
|
return this.cardRepository.findOne({ where: { cardReference: referenceNumber }, relations: ['account'] });
|
|
}
|
|
|
|
getCardByVpan(vpan: string): Promise<Card | null> {
|
|
return this.cardRepository.findOne({
|
|
where: { vpan },
|
|
relations: ['account'],
|
|
});
|
|
}
|
|
|
|
getCardByCustomerId(customerId: string): Promise<Card | null> {
|
|
return this.cardRepository.findOne({
|
|
where: { customerId },
|
|
relations: ['account'],
|
|
});
|
|
}
|
|
|
|
updateCardStatus(id: string, status: CardStatus, statusDescription: CardStatusDescription) {
|
|
return this.cardRepository.update(id, {
|
|
status: status,
|
|
statusDescription: statusDescription,
|
|
});
|
|
}
|
|
}
|