import * as repo from './repository.js'; import { HttpError } from '../../utils/http.js'; // Siempre privadas: cada quien ve y toca solo sus propias notas, sin importar el rol. Una nota // de otro usuario responde 404 (no 403) para no revelar que existe. async function getOwnNoteOr404(id, currentUser) { const note = await repo.findById(id); if (!note || note.user_id !== currentUser.id) throw new HttpError(404, 'Nota no encontrada'); return note; } export const listNotes = (currentUser) => repo.findByUser(currentUser.id); export async function createNote(content, currentUser) { const trimmed = (content || '').trim(); if (!trimmed) throw new HttpError(400, 'El contenido es obligatorio'); return repo.create(currentUser.id, trimmed); } export async function updateNote(id, content, currentUser) { await getOwnNoteOr404(id, currentUser); const trimmed = (content || '').trim(); if (!trimmed) throw new HttpError(400, 'El contenido es obligatorio'); return repo.update(id, trimmed); } export async function removeNote(id, currentUser) { await getOwnNoteOr404(id, currentUser); await repo.remove(id); }