Files
boc/packages/infrastructure/src/adapters/in-memory-decision-case-repository.ts
T

48 lines
1.2 KiB
TypeScript
Raw Normal View History

/**
* In-Memory DecisionCase Repository
*
* Adapter: Implements DecisionCaseRepository using a Map.
* Purpose: Testing, development, CI/CD pipelines.
* NOT for production.
*/
import {
DecisionCase,
DecisionCaseId,
ArtifactId,
EvidenceId,
} from '@landvex/domain';
import { DecisionCaseRepository } from '../repositories/repository-interfaces';
export class InMemoryDecisionCaseRepository implements DecisionCaseRepository {
private cases = new Map<string, DecisionCase>();
async save(decisionCase: DecisionCase): Promise<void> {
this.cases.set(decisionCase.id, decisionCase);
}
async findById(id: DecisionCaseId): Promise<DecisionCase | null> {
return this.cases.get(id) ?? null;
}
async findByArtifact(artifactId: ArtifactId): Promise<DecisionCase[]> {
return Array.from(this.cases.values())
.filter(c => c.evidenceIds.includes(artifactId as any));
}
async findByStatus(
status: 'pending' | 'under_review' | 'approved' | 'rejected'
): Promise<DecisionCase[]> {
return Array.from(this.cases.values())
.filter(c => c.status === status);
}
clear(): void {
this.cases.clear();
}
count(): number {
return this.cases.size;
}
}