Files
gridpilot.gg/packages/racing/infrastructure/repositories/InMemorySessionRepository.ts
2025-12-13 11:43:09 +01:00

62 lines
1.6 KiB
TypeScript

/**
* In-memory implementation of ISessionRepository for development/testing.
*/
import type { ISessionRepository } from '../../domain/repositories/ISessionRepository';
import type { Session } from '../../domain/entities/Session';
export class InMemorySessionRepository implements ISessionRepository {
private sessions: Map<string, Session> = new Map();
async findById(id: string): Promise<Session | null> {
return this.sessions.get(id) ?? null;
}
async findAll(): Promise<Session[]> {
return Array.from(this.sessions.values());
}
async findByRaceEventId(raceEventId: string): Promise<Session[]> {
return Array.from(this.sessions.values()).filter(
session => session.raceEventId === raceEventId
);
}
async findByLeagueId(leagueId: string): Promise<Session[]> {
// Sessions don't have leagueId directly - would need to join with RaceEvent
// For now, return empty array
return [];
}
async findByStatus(status: string): Promise<Session[]> {
return Array.from(this.sessions.values()).filter(
session => session.status === status
);
}
async create(session: Session): Promise<Session> {
this.sessions.set(session.id, session);
return session;
}
async update(session: Session): Promise<Session> {
this.sessions.set(session.id, session);
return session;
}
async delete(id: string): Promise<void> {
this.sessions.delete(id);
}
async exists(id: string): Promise<boolean> {
return this.sessions.has(id);
}
// Test helper methods
clear(): void {
this.sessions.clear();
}
getAll(): Session[] {
return Array.from(this.sessions.values());
}
}