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:
Milton Gonzalez
2026-09-17 15:54:05 -05:00
parent 9089f2ff7a
commit ceda779b75
17 changed files with 268 additions and 4 deletions
+28
View File
@@ -0,0 +1,28 @@
import { pool } from '../../config/db.js';
export async function findByUser(userId) {
const [rows] = await pool.query(
'SELECT id, user_id, content, created_at, updated_at FROM notes WHERE user_id = ? ORDER BY updated_at DESC',
[userId]
);
return rows;
}
export async function findById(id) {
const [rows] = await pool.query('SELECT id, user_id, content, created_at, updated_at FROM notes WHERE id = ?', [id]);
return rows[0] || null;
}
export async function create(userId, content) {
const [result] = await pool.query('INSERT INTO notes (user_id, content) VALUES (?, ?)', [userId, content]);
return findById(result.insertId);
}
export async function update(id, content) {
await pool.query('UPDATE notes SET content = ? WHERE id = ?', [content, id]);
return findById(id);
}
export async function remove(id) {
await pool.query('DELETE FROM notes WHERE id = ?', [id]);
}