Merge pull request #5 from R0m1k3/claude/dockerized-notes-todo-app-011CV1roGRbnm21wgtB2LMxP

Correction de l'erreur 500 sur /api/notes et gestion robuste côté client
This commit is contained in:
LogiFlow authored and GitHub committed 2025-11-11 12:29:13 +01:00
commit e2739eb0e9
2 files changed
+12 -5

No files matched your search

+10 -1
View File
@@ -184,10 +184,14 @@ async function initAuth() {
// ==================== NOTES ====================
async function loadNotes() {
try {
state.notes = await api.get('/api/notes');
const response = await api.get('/api/notes');
// S'assurer que response est un tableau
state.notes = Array.isArray(response) ? response : [];
renderNotes();
} catch (error) {
console.error('Erreur chargement notes:', error);
state.notes = [];
renderNotes();
}
}
@@ -195,6 +199,11 @@ function renderNotes() {
const notesGrid = document.getElementById('notesGrid');
if (!notesGrid) return;
// S'assurer que state.notes est toujours un tableau
if (!Array.isArray(state.notes)) {
state.notes = [];
}
let filtered = state.notes;
// Filtre de recherche
+2 -4
View File
@@ -48,15 +48,13 @@ router.get('/', async (req, res) => {
SELECT
n.id, n.title, n.content, n.image_filename,
n.created_at, n.updated_at,
COUNT(DISTINCT nt.id) as todos_count
(SELECT COUNT(*) FROM note_todos WHERE note_id = n.id) as todos_count
FROM notes n
LEFT JOIN note_todos nt ON n.id = nt.note_id
WHERE n.user_id = ?
GROUP BY n.id
ORDER BY n.updated_at DESC
`, [req.user.id]);
res.json(notes);
res.json(notes || []);
} catch (error) {
logger.error('Erreur lors de la récupération des notes:', error);
res.status(500).json({ error: 'Erreur serveur' });