54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
/**
|
|
* In-Memory Implementation: InMemoryPrizeRepository
|
|
*/
|
|
|
|
import type { Prize } from '@core/payments/domain/entities/Prize';
|
|
import type { PrizeRepository } from '@core/payments/domain/repositories/PrizeRepository';
|
|
import type { Logger } from '@core/shared/domain/Logger';
|
|
|
|
const prizes: Map<string, Prize> = new Map();
|
|
|
|
export class InMemoryPrizeRepository implements PrizeRepository {
|
|
constructor(private readonly logger: Logger) {}
|
|
|
|
async findById(id: string): Promise<Prize | null> {
|
|
this.logger.debug('[InMemoryPrizeRepository] findById', { id });
|
|
return prizes.get(id) || null;
|
|
}
|
|
|
|
async findByLeagueId(leagueId: string): Promise<Prize[]> {
|
|
this.logger.debug('[InMemoryPrizeRepository] findByLeagueId', { leagueId });
|
|
return Array.from(prizes.values()).filter(p => p.leagueId === leagueId);
|
|
}
|
|
|
|
async findByLeagueIdAndSeasonId(leagueId: string, seasonId: string): Promise<Prize[]> {
|
|
this.logger.debug('[InMemoryPrizeRepository] findByLeagueIdAndSeasonId', { leagueId, seasonId });
|
|
return Array.from(prizes.values()).filter(
|
|
p => p.leagueId === leagueId && p.seasonId === seasonId
|
|
);
|
|
}
|
|
|
|
async findByPosition(leagueId: string, seasonId: string, position: number): Promise<Prize | null> {
|
|
this.logger.debug('[InMemoryPrizeRepository] findByPosition', { leagueId, seasonId, position });
|
|
return Array.from(prizes.values()).find(
|
|
p => p.leagueId === leagueId && p.seasonId === seasonId && p.position === position
|
|
) || null;
|
|
}
|
|
|
|
async create(prize: Prize): Promise<Prize> {
|
|
this.logger.debug('[InMemoryPrizeRepository] create', { prize });
|
|
prizes.set(prize.id, prize);
|
|
return prize;
|
|
}
|
|
|
|
async update(prize: Prize): Promise<Prize> {
|
|
this.logger.debug('[InMemoryPrizeRepository] update', { prize });
|
|
prizes.set(prize.id, prize);
|
|
return prize;
|
|
}
|
|
|
|
async delete(id: string): Promise<void> {
|
|
this.logger.debug('[InMemoryPrizeRepository] delete', { id });
|
|
prizes.delete(id);
|
|
}
|
|
} |