Task 20 of the slice plan. Thin wrapper over the repo's intent methods that adds two preconditions: setIntent rejects empty trimmed text, both methods throw "note not found" when the note id doesn't exist. Repo-level COALESCE on intent_prompted_at preserves the first-prompt invariant (spec §3.3); IntentService's job is just input guarding so the IPC handler stays a one-liner. Verification: `npx vitest run tests/unit/IntentService.test.ts` 4 passed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
17 lines
542 B
TypeScript
17 lines
542 B
TypeScript
import type { NoteRepository } from '../repository/NoteRepository.js';
|
|
|
|
export class IntentService {
|
|
constructor(private repo: NoteRepository) {}
|
|
|
|
setIntent(noteId: string, text: string): void {
|
|
if (text.trim().length === 0) throw new Error('empty intent text');
|
|
if (!this.repo.findById(noteId)) throw new Error('note not found');
|
|
this.repo.setIntent(noteId, text);
|
|
}
|
|
|
|
dismissIntent(noteId: string): void {
|
|
if (!this.repo.findById(noteId)) throw new Error('note not found');
|
|
this.repo.dismissIntent(noteId);
|
|
}
|
|
}
|