From e420364b503831fc452bd7bd5956596746a2da69 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 27 Nov 2025 12:49:07 +0000 Subject: [PATCH] fix: correct SQL bug in todo creation query Fixed critical SQL type error in todo creation endpoint that prevented todos from being added to notes. Bug: - Line 417: Used FALSE (boolean) instead of 0 (integer) in COALESCE function - SQL: COALESCE(MAX(position), FALSE) + 1 - This caused a type mismatch error when inserting new todos Fix: - Changed to: COALESCE(MAX(position), 0) + 1 - Now correctly defaults to 0 when no todos exist for a note This fix resolves the issue where adding todos would fail silently or throw database errors. --- routes/notes.routes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/notes.routes.js b/routes/notes.routes.js index 98a8977..14650e3 100644 --- a/routes/notes.routes.js +++ b/routes/notes.routes.js @@ -414,7 +414,7 @@ router.post('/:id/todos', const result = await runQuery(` INSERT INTO note_todos (note_id, text, position) - VALUES ($1, $2, (SELECT COALESCE(MAX(position), FALSE) + 1 FROM note_todos WHERE note_id = $3)) + VALUES ($1, $2, (SELECT COALESCE(MAX(position), 0) + 1 FROM note_todos WHERE note_id = $3)) RETURNING * `, [req.params.id, text, req.params.id]);