51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
|
|
/**
|
||
|
|
* In-Memory FieldSession Repository
|
||
|
|
*
|
||
|
|
* Adapter: Implements FieldSessionRepository using a Map.
|
||
|
|
* Purpose: Testing, development, CI/CD pipelines.
|
||
|
|
* NOT for production.
|
||
|
|
*
|
||
|
|
* ADR-006: In-memory adapters for testing
|
||
|
|
* - Fast, isolated, no external dependencies
|
||
|
|
* - Reset between tests
|
||
|
|
* - Never used in production
|
||
|
|
*/
|
||
|
|
|
||
|
|
import {
|
||
|
|
FieldSession,
|
||
|
|
SessionId,
|
||
|
|
} from '@landvex/domain';
|
||
|
|
import { FieldSessionRepository } from '../repositories/repository-interfaces';
|
||
|
|
|
||
|
|
export class InMemoryFieldSessionRepository implements FieldSessionRepository {
|
||
|
|
private sessions = new Map<string, FieldSession>();
|
||
|
|
|
||
|
|
async save(session: FieldSession): Promise<void> {
|
||
|
|
this.sessions.set(session.id, session);
|
||
|
|
}
|
||
|
|
|
||
|
|
async findById(id: SessionId): Promise<FieldSession | null> {
|
||
|
|
return this.sessions.get(id) ?? null;
|
||
|
|
}
|
||
|
|
|
||
|
|
async findActive(): Promise<FieldSession[]> {
|
||
|
|
return Array.from(this.sessions.values())
|
||
|
|
.filter(s => s.status === 'planned' || s.status === 'active');
|
||
|
|
}
|
||
|
|
|
||
|
|
async findByDateRange(start: Date, end: Date): Promise<FieldSession[]> {
|
||
|
|
return Array.from(this.sessions.values())
|
||
|
|
.filter(s => s.date >= start && s.date <= end);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Reset for testing */
|
||
|
|
clear(): void {
|
||
|
|
this.sessions.clear();
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Count for assertions */
|
||
|
|
count(): number {
|
||
|
|
return this.sessions.size;
|
||
|
|
}
|
||
|
|
}
|