Domain service for Note business logic.
Encapsulates complex business rules that don't belong to a single entity. Uses dependency injection for repository access.
const queryRepo: INotesQueryRepository = new PrismaNotesQueryRepository();const domainService = new NotesDomainService(queryRepo);try { await domainService.ensureNoDuplicate(title, userId); // Safe to create the note} catch (error) { if (error instanceof DuplicateError) { // Handle duplicate title }} Copy
const queryRepo: INotesQueryRepository = new PrismaNotesQueryRepository();const domainService = new NotesDomainService(queryRepo);try { await domainService.ensureNoDuplicate(title, userId); // Safe to create the note} catch (error) { if (error instanceof DuplicateError) { // Handle duplicate title }}
Creates a new NotesDomainService instance.
The query repository for checking duplicates
Validates that no note with the same title exists for the user.
The title to check for duplicates
The user ID for tenant isolation
When a note with this title already exists
This is a domain invariant check that should be called before creating notes.
Domain service for Note business logic.
Remarks
Encapsulates complex business rules that don't belong to a single entity. Uses dependency injection for repository access.
Example
See