diff --git a/config/database.js b/config/database.js
index f5749d9..e1d55f6 100644
--- a/config/database.js
+++ b/config/database.js
@@ -123,11 +123,22 @@ async function initDatabase() {
archived BOOLEAN DEFAULT FALSE,
archived_at TIMESTAMP,
priority INTEGER DEFAULT 0,
+ created_via VARCHAR(20) DEFAULT 'web',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
`);
+ // Migration: ajouter la colonne created_via si elle n'existe pas
+ await client.query(`
+ DO $$
+ BEGIN
+ IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'notes' AND column_name = 'created_via') THEN
+ ALTER TABLE notes ADD COLUMN created_via VARCHAR(20) DEFAULT 'web';
+ END IF;
+ END $$;
+ `);
+
// Table note_todos
await client.query(`
CREATE TABLE IF NOT EXISTS note_todos (
diff --git a/routes/notes.routes.js b/routes/notes.routes.js
index f24a084..b5cfd33 100644
--- a/routes/notes.routes.js
+++ b/routes/notes.routes.js
@@ -74,7 +74,7 @@ router.get('/', async (req, res) => {
const notes = await getAll(`
SELECT
n.id, n.title, n.content, n.image_filename, n.archived, n.priority,
- n.created_at, n.updated_at,
+ n.created_via, n.created_at, n.updated_at,
(SELECT COUNT(*) FROM note_todos WHERE note_id = n.id) as todos_count,
(SELECT COUNT(*) FROM note_todos WHERE note_id = n.id AND completed = TRUE) as todos_completed
FROM notes n
@@ -242,10 +242,10 @@ router.post('/full',
logger.info(`[CREATE NOTE FULL] Début création - user_id: ${req.user.id}, title: "${title}", todos: ${todos.length}, tags: ${tags.length}`);
- // 1. Créer la note
+ // 1. Créer la note (marquée comme créée via API)
const noteResult = await runQuery(`
- INSERT INTO notes (user_id, title, content)
- VALUES ($1, $2, $3)
+ INSERT INTO notes (user_id, title, content, created_via)
+ VALUES ($1, $2, $3, 'api')
RETURNING *
`, [req.user.id, title, content || '']);
@@ -325,6 +325,7 @@ router.post('/full',
image_filename: null,
archived: false,
priority: 0,
+ created_via: 'api',
todos: createdTodos,
tags: createdTags,
images: [],
diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx
index 4152632..dd7c2d2 100644
--- a/src/pages/Index.tsx
+++ b/src/pages/Index.tsx
@@ -1397,7 +1397,7 @@ const Index = () => {
paginatedNotes.map(note => (