mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-11 17:29:37 +02:00
Fix: Erreurs 500 lors mise à jour notes - SQL dynamique non converti
Problème: PUT /api/notes/:id retourne 500 Internal Server Error
- Script convert-sql-to-postgres.js a manqué les requêtes SQL dynamiques
- Routes utilisaient encore syntaxe SQLite (?) dans les updates dynamiques
- Erreur: "bind message supplies 2 parameters, but prepared statement requires 0"
Fichiers corrigés:
- routes/notes.routes.js:219-236 (PUT /api/notes/:id)
- routes/notes.routes.js:444-469 (PUT /api/notes/todos/:todoId)
- routes/todos.routes.js:92-111 (PUT /api/todos/:id)
Solution:
- Ajout compteur paramCount pour numérotation PostgreSQL
- Remplacement ? par $1, $2, $3... dans updates dynamiques
- Exemple: 'title = ?' → `title = $${paramCount}`
Résultat: Notes peuvent maintenant être éditées sans erreur 500
This commit is contained in:
2 files changed
+23
-10
No files matched your search
+16
-7
@@ -214,21 +214,25 @@ router.put('/:id',
|
|||||||
|
|
||||||
const updates = [];
|
const updates = [];
|
||||||
const params = [];
|
const params = [];
|
||||||
|
let paramCount = 0;
|
||||||
|
|
||||||
if (title !== undefined) {
|
if (title !== undefined) {
|
||||||
updates.push('title = ?');
|
paramCount++;
|
||||||
|
updates.push(`title = $${paramCount}`);
|
||||||
params.push(title);
|
params.push(title);
|
||||||
}
|
}
|
||||||
if (content !== undefined) {
|
if (content !== undefined) {
|
||||||
updates.push('content = ?');
|
paramCount++;
|
||||||
|
updates.push(`content = $${paramCount}`);
|
||||||
params.push(content);
|
params.push(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updates.length > 0) {
|
if (updates.length > 0) {
|
||||||
updates.push('updated_at = CURRENT_TIMESTAMP');
|
updates.push('updated_at = CURRENT_TIMESTAMP');
|
||||||
|
paramCount++;
|
||||||
params.push(req.params.id);
|
params.push(req.params.id);
|
||||||
|
|
||||||
await runQuery(`UPDATE notes SET ${updates.join(', ')} WHERE id = ?`, params);
|
await runQuery(`UPDATE notes SET ${updates.join(', ')} WHERE id = $${paramCount}`, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({ message: 'Note modifiée avec succès' });
|
res.json({ message: 'Note modifiée avec succès' });
|
||||||
@@ -439,23 +443,28 @@ router.put('/todos/:todoId',
|
|||||||
|
|
||||||
const updates = [];
|
const updates = [];
|
||||||
const params = [];
|
const params = [];
|
||||||
|
let paramCount = 0;
|
||||||
|
|
||||||
if (text !== undefined) {
|
if (text !== undefined) {
|
||||||
updates.push('text = ?');
|
paramCount++;
|
||||||
|
updates.push(`text = $${paramCount}`);
|
||||||
params.push(text);
|
params.push(text);
|
||||||
}
|
}
|
||||||
if (completed !== undefined) {
|
if (completed !== undefined) {
|
||||||
updates.push('completed = ?');
|
paramCount++;
|
||||||
|
updates.push(`completed = $${paramCount}`);
|
||||||
params.push(completed ? 1 : 0);
|
params.push(completed ? 1 : 0);
|
||||||
}
|
}
|
||||||
if (position !== undefined) {
|
if (position !== undefined) {
|
||||||
updates.push('position = ?');
|
paramCount++;
|
||||||
|
updates.push(`position = $${paramCount}`);
|
||||||
params.push(position);
|
params.push(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updates.length > 0) {
|
if (updates.length > 0) {
|
||||||
|
paramCount++;
|
||||||
params.push(req.params.todoId);
|
params.push(req.params.todoId);
|
||||||
await runQuery(`UPDATE note_todos SET ${updates.join(', ')} WHERE id = ?`, params);
|
await runQuery(`UPDATE note_todos SET ${updates.join(', ')} WHERE id = $${paramCount}`, params);
|
||||||
await runQuery('UPDATE notes SET updated_at = CURRENT_TIMESTAMP WHERE id = $1', [todo.note_id]);
|
await runQuery('UPDATE notes SET updated_at = CURRENT_TIMESTAMP WHERE id = $1', [todo.note_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,19 +91,23 @@ router.put('/:id',
|
|||||||
|
|
||||||
const updates = [];
|
const updates = [];
|
||||||
const params = [];
|
const params = [];
|
||||||
|
let paramCount = 0;
|
||||||
|
|
||||||
if (text !== undefined) {
|
if (text !== undefined) {
|
||||||
updates.push('text = ?');
|
paramCount++;
|
||||||
|
updates.push(`text = $${paramCount}`);
|
||||||
params.push(text);
|
params.push(text);
|
||||||
}
|
}
|
||||||
if (completed !== undefined) {
|
if (completed !== undefined) {
|
||||||
updates.push('completed = ?');
|
paramCount++;
|
||||||
|
updates.push(`completed = $${paramCount}`);
|
||||||
params.push(completed ? 1 : 0);
|
params.push(completed ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updates.length > 0) {
|
if (updates.length > 0) {
|
||||||
|
paramCount++;
|
||||||
params.push(req.params.id);
|
params.push(req.params.id);
|
||||||
await runQuery(`UPDATE global_todos SET ${updates.join(', ')} WHERE id = ?`, params);
|
await runQuery(`UPDATE global_todos SET ${updates.join(', ')} WHERE id = $${paramCount}`, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({ message: 'Todo modifié avec succès' });
|
res.json({ message: 'Todo modifié avec succès' });
|
||||||
|
|||||||
Reference in new issue
Block a user