feat: menu Notas -- apuntes rapidos personales
Nuevo menu "Notas" en el sidebar: crear, editar y eliminar apuntes rapidos, con fecha y hora de creacion (y de ultima edicion si aplica). Siempre privadas de cada usuario -- una nota de otro usuario responde 404, no 403, para no revelar que existe. Sin restriccion de rol. Nuevo notes (tabla) + GET/POST/PUT/DELETE /api/notes. Probado de punta a punta en dev: crear, editar, borrar y el formato de fecha/hora funcionan correctamente. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user