File size: 914 Bytes
d47b053 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import type { StudioTask, StudioTaskStore } from '../domain/types'
export class InMemoryStudioTaskStore implements StudioTaskStore {
private readonly tasks = new Map<string, StudioTask>()
async create(task: StudioTask): Promise<StudioTask> {
this.tasks.set(task.id, task)
return task
}
async getById(taskId: string): Promise<StudioTask | null> {
return this.tasks.get(taskId) ?? null
}
async update(taskId: string, patch: Partial<StudioTask>): Promise<StudioTask | null> {
const current = this.tasks.get(taskId)
if (!current) {
return null
}
const next: StudioTask = {
...current,
...patch,
updatedAt: new Date().toISOString()
}
this.tasks.set(taskId, next)
return next
}
async listBySessionId(sessionId: string): Promise<StudioTask[]> {
return [...this.tasks.values()].filter((task) => task.sessionId === sessionId)
}
}
|