wip
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* 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<string, Sponsor> = new Map();
|
||||
|
||||
async findById(id: string): Promise<Sponsor | null> {
|
||||
return this.sponsors.get(id) ?? null;
|
||||
}
|
||||
|
||||
async findAll(): Promise<Sponsor[]> {
|
||||
return Array.from(this.sponsors.values());
|
||||
}
|
||||
|
||||
async findByEmail(email: string): Promise<Sponsor | null> {
|
||||
for (const sponsor of this.sponsors.values()) {
|
||||
if (sponsor.contactEmail === email) {
|
||||
return sponsor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async create(sponsor: Sponsor): Promise<Sponsor> {
|
||||
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<Sponsor> {
|
||||
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<void> {
|
||||
this.sponsors.delete(id);
|
||||
}
|
||||
|
||||
async exists(id: string): Promise<boolean> {
|
||||
return this.sponsors.has(id);
|
||||
}
|
||||
|
||||
// Test helper
|
||||
clear(): void {
|
||||
this.sponsors.clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user