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.
This commit is contained in:
Claude committed 2025-11-27 12:49:07 +00:00
1 parent 2b7d824c22
commit e420364b50
1 file changed
+1 -1
+1 -1
View File
@@ -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]);