62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
/**
|
|
* In-Memory Implementation: InMemoryPaymentRepository
|
|
*/
|
|
|
|
import type { Payment, PaymentType } from '@core/payments/domain/entities/Payment';
|
|
import type { PaymentRepository } from '@core/payments/domain/repositories/PaymentRepository';
|
|
import type { Logger } from '@core/shared/domain/Logger';
|
|
|
|
const payments: Map<string, Payment> = new Map();
|
|
|
|
export class InMemoryPaymentRepository implements PaymentRepository {
|
|
constructor(private readonly logger: Logger) {}
|
|
|
|
async findById(id: string): Promise<Payment | null> {
|
|
this.logger.debug('[InMemoryPaymentRepository] findById', { id });
|
|
return payments.get(id) || null;
|
|
}
|
|
|
|
async findByLeagueId(leagueId: string): Promise<Payment[]> {
|
|
this.logger.debug('[InMemoryPaymentRepository] findByLeagueId', { leagueId });
|
|
return Array.from(payments.values()).filter(p => p.leagueId === leagueId);
|
|
}
|
|
|
|
async findByPayerId(payerId: string): Promise<Payment[]> {
|
|
this.logger.debug('[InMemoryPaymentRepository] findByPayerId', { payerId });
|
|
return Array.from(payments.values()).filter(p => p.payerId === payerId);
|
|
}
|
|
|
|
async findByType(type: PaymentType): Promise<Payment[]> {
|
|
this.logger.debug('[InMemoryPaymentRepository] findByType', { type });
|
|
return Array.from(payments.values()).filter(p => p.type === type);
|
|
}
|
|
|
|
async findByFilters(filters: { leagueId?: string; payerId?: string; type?: PaymentType }): Promise<Payment[]> {
|
|
this.logger.debug('[InMemoryPaymentRepository] findByFilters', { filters });
|
|
let results = Array.from(payments.values());
|
|
|
|
if (filters.leagueId) {
|
|
results = results.filter(p => p.leagueId === filters.leagueId);
|
|
}
|
|
if (filters.payerId) {
|
|
results = results.filter(p => p.payerId === filters.payerId);
|
|
}
|
|
if (filters.type) {
|
|
results = results.filter(p => p.type === filters.type);
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
async create(payment: Payment): Promise<Payment> {
|
|
this.logger.debug('[InMemoryPaymentRepository] create', { payment });
|
|
payments.set(payment.id, payment);
|
|
return payment;
|
|
}
|
|
|
|
async update(payment: Payment): Promise<Payment> {
|
|
this.logger.debug('[InMemoryPaymentRepository] update', { payment });
|
|
payments.set(payment.id, payment);
|
|
return payment;
|
|
}
|
|
} |