mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-11 17:29:37 +02:00
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:
2 files changed
+12
-5
No files matched your search
@@ -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
|
||||
|
||||
@@ -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' });
|
||||
|
||||
Reference in new issue
Block a user