Files
gridpilot.gg/packages/racing/infrastructure/repositories/InMemorySeasonSponsorshipRepository.ts
2025-12-12 14:23:40 +01:00

72 lines
2.3 KiB
TypeScript

/**
* In-Memory Implementation: ISeasonSponsorshipRepository
*
* Mock repository for testing and development
*/
import type { SeasonSponsorship, SponsorshipTier } from '../../domain/entities/SeasonSponsorship';
import type { ISeasonSponsorshipRepository } from '../../domain/repositories/ISeasonSponsorshipRepository';
export class InMemorySeasonSponsorshipRepository implements ISeasonSponsorshipRepository {
private sponsorships: Map<string, SeasonSponsorship> = new Map();
async findById(id: string): Promise<SeasonSponsorship | null> {
return this.sponsorships.get(id) ?? null;
}
async findBySeasonId(seasonId: string): Promise<SeasonSponsorship[]> {
return Array.from(this.sponsorships.values()).filter(s => s.seasonId === seasonId);
}
async findByLeagueId(leagueId: string): Promise<SeasonSponsorship[]> {
return Array.from(this.sponsorships.values()).filter(s => s.leagueId === leagueId);
}
async findBySponsorId(sponsorId: string): Promise<SeasonSponsorship[]> {
return Array.from(this.sponsorships.values()).filter(s => s.sponsorId === sponsorId);
}
async findBySeasonAndTier(seasonId: string, tier: SponsorshipTier): Promise<SeasonSponsorship[]> {
return Array.from(this.sponsorships.values()).filter(
s => s.seasonId === seasonId && s.tier === tier
);
}
async create(sponsorship: SeasonSponsorship): Promise<SeasonSponsorship> {
if (this.sponsorships.has(sponsorship.id)) {
throw new Error('SeasonSponsorship with this ID already exists');
}
this.sponsorships.set(sponsorship.id, sponsorship);
return sponsorship;
}
async update(sponsorship: SeasonSponsorship): Promise<SeasonSponsorship> {
if (!this.sponsorships.has(sponsorship.id)) {
throw new Error('SeasonSponsorship not found');
}
this.sponsorships.set(sponsorship.id, sponsorship);
return sponsorship;
}
async delete(id: string): Promise<void> {
this.sponsorships.delete(id);
}
async exists(id: string): Promise<boolean> {
return this.sponsorships.has(id);
}
/**
* Seed initial data
*/
seed(sponsorships: SeasonSponsorship[]): void {
for (const sponsorship of sponsorships) {
this.sponsorships.set(sponsorship.id, sponsorship);
}
}
// Test helper
clear(): void {
this.sponsorships.clear();
}
}