/** * In-Memory Implementation: ISponsorRepository * * Mock repository for testing and development */ import type { Sponsor } from '../../domain/entities/Sponsor'; import type { ISponsorRepository } from '../../domain/repositories/ISponsorRepository'; export class InMemorySponsorRepository implements ISponsorRepository { private sponsors: Map = new Map(); async findById(id: string): Promise { return this.sponsors.get(id) ?? null; } async findAll(): Promise { return Array.from(this.sponsors.values()); } async findByEmail(email: string): Promise { for (const sponsor of this.sponsors.values()) { if (sponsor.contactEmail === email) { return sponsor; } } return null; } async create(sponsor: Sponsor): Promise { if (this.sponsors.has(sponsor.id)) { throw new Error('Sponsor with this ID already exists'); } this.sponsors.set(sponsor.id, sponsor); return sponsor; } async update(sponsor: Sponsor): Promise { if (!this.sponsors.has(sponsor.id)) { throw new Error('Sponsor not found'); } this.sponsors.set(sponsor.id, sponsor); return sponsor; } async delete(id: string): Promise { this.sponsors.delete(id); } async exists(id: string): Promise { return this.sponsors.has(id); } /** * Seed initial data */ seed(sponsors: Sponsor[]): void { for (const sponsor of sponsors) { this.sponsors.set(sponsor.id, sponsor); } } // Test helper clear(): void { this.sponsors.clear(); } }