mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-11 17:29:37 +02:00
Correction de l'erreur 500 sur /api/notes et gestion robuste côté client
- Remplacement de COUNT(DISTINCT) par une sous-requête dans SQLite - Ajout de vérification Array.isArray côté client - Gestion d'erreur améliorée avec fallback sur tableau vide - Correction du bug 'filtered.forEach is not a function' - L'API retourne toujours un tableau, même en cas d'erreur
This commit is contained in:
2 files changed
+12
-5
No files matched your search
@@ -184,10 +184,14 @@ async function initAuth() {
|
|||||||
// ==================== NOTES ====================
|
// ==================== NOTES ====================
|
||||||
async function loadNotes() {
|
async function loadNotes() {
|
||||||
try {
|
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();
|
renderNotes();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur chargement notes:', error);
|
console.error('Erreur chargement notes:', error);
|
||||||
|
state.notes = [];
|
||||||
|
renderNotes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,6 +199,11 @@ function renderNotes() {
|
|||||||
const notesGrid = document.getElementById('notesGrid');
|
const notesGrid = document.getElementById('notesGrid');
|
||||||
if (!notesGrid) return;
|
if (!notesGrid) return;
|
||||||
|
|
||||||
|
// S'assurer que state.notes est toujours un tableau
|
||||||
|
if (!Array.isArray(state.notes)) {
|
||||||
|
state.notes = [];
|
||||||
|
}
|
||||||
|
|
||||||
let filtered = state.notes;
|
let filtered = state.notes;
|
||||||
|
|
||||||
// Filtre de recherche
|
// Filtre de recherche
|
||||||
|
|||||||
@@ -48,15 +48,13 @@ router.get('/', async (req, res) => {
|
|||||||
SELECT
|
SELECT
|
||||||
n.id, n.title, n.content, n.image_filename,
|
n.id, n.title, n.content, n.image_filename,
|
||||||
n.created_at, n.updated_at,
|
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
|
FROM notes n
|
||||||
LEFT JOIN note_todos nt ON n.id = nt.note_id
|
|
||||||
WHERE n.user_id = ?
|
WHERE n.user_id = ?
|
||||||
GROUP BY n.id
|
|
||||||
ORDER BY n.updated_at DESC
|
ORDER BY n.updated_at DESC
|
||||||
`, [req.user.id]);
|
`, [req.user.id]);
|
||||||
|
|
||||||
res.json(notes);
|
res.json(notes || []);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Erreur lors de la récupération des notes:', error);
|
logger.error('Erreur lors de la récupération des notes:', error);
|
||||||
res.status(500).json({ error: 'Erreur serveur' });
|
res.status(500).json({ error: 'Erreur serveur' });
|
||||||
|
|||||||
Reference in new issue
Block a user