36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { AutomationSession } from '../../domain/entities/AutomationSession';
|
|
import { SessionStateValue } from '../../domain/value-objects/SessionState';
|
|
import type { SessionRepositoryPort } from '../../application/ports/SessionRepositoryPort';
|
|
|
|
export class InMemorySessionRepository implements SessionRepositoryPort {
|
|
private sessions: Map<string, AutomationSession> = new Map();
|
|
|
|
async save(session: AutomationSession): Promise<void> {
|
|
this.sessions.set(session.id, session);
|
|
}
|
|
|
|
async findById(id: string): Promise<AutomationSession | null> {
|
|
return this.sessions.get(id) || null;
|
|
}
|
|
|
|
async update(session: AutomationSession): Promise<void> {
|
|
if (!this.sessions.has(session.id)) {
|
|
throw new Error('Session not found');
|
|
}
|
|
this.sessions.set(session.id, session);
|
|
}
|
|
|
|
async delete(id: string): Promise<void> {
|
|
this.sessions.delete(id);
|
|
}
|
|
|
|
async findAll(): Promise<AutomationSession[]> {
|
|
return Array.from(this.sessions.values());
|
|
}
|
|
|
|
async findByState(state: SessionStateValue): Promise<AutomationSession[]> {
|
|
return Array.from(this.sessions.values()).filter(
|
|
session => session.state.value === state
|
|
);
|
|
}
|
|
} |