mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-11 17:29:37 +02:00
Merge pull request #135 from R0m1k3/claude/fix-notes-sync-issue-01AMeEdrKQErsM7bvhKkqEEF
fix: correct PostgreSQL boolean type handling across all routes
This commit is contained in:
6 files changed
+19
-19
No files matched your search
@@ -853,7 +853,7 @@ router.put('/events/:id', authenticateToken, async (req, res) => {
|
||||
endTimeUTC,
|
||||
location || null,
|
||||
response.data.htmlLink || null,
|
||||
isAllDay ? 1 : 0,
|
||||
isAllDay, // BOOLEAN instead of 0/1
|
||||
req.params.id
|
||||
]);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ router.use(authenticateToken);
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const showArchived = req.query.archived === 'true';
|
||||
const archivedFilter = showArchived ? 1 : 0;
|
||||
const archivedFilter = showArchived; // BOOLEAN instead of 0/1
|
||||
|
||||
const notes = await getAll(`
|
||||
SELECT
|
||||
@@ -274,7 +274,7 @@ router.put('/:id/archive', async (req, res) => {
|
||||
|
||||
await runQuery(
|
||||
'UPDATE notes SET archived = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2',
|
||||
[archived ? 1 : 0, req.params.id]
|
||||
[archived, req.params.id] // BOOLEAN instead of 0/1
|
||||
);
|
||||
|
||||
logger.info(`Note ${archived ? 'archivée' : 'désarchivée'}: ${req.params.id}`);
|
||||
@@ -488,7 +488,7 @@ router.put('/todos/:todoId',
|
||||
if (completed !== undefined) {
|
||||
paramCount++;
|
||||
updates.push(`completed = $${paramCount}`);
|
||||
params.push(completed ? 1 : 0);
|
||||
params.push(completed); // BOOLEAN instead of 0/1
|
||||
}
|
||||
if (position !== undefined) {
|
||||
paramCount++;
|
||||
@@ -972,7 +972,7 @@ router.patch('/:id/priority', async (req, res) => {
|
||||
return res.status(404).json({ error: 'Note non trouvée' });
|
||||
}
|
||||
|
||||
await runQuery('UPDATE notes SET priority = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2', [priority ? 1 : 0, req.params.id]);
|
||||
await runQuery('UPDATE notes SET priority = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2', [priority, req.params.id]); // BOOLEAN instead of 0/1
|
||||
|
||||
logger.info(`Priorité de la note ${req.params.id} modifiée: ${priority}`);
|
||||
res.json({ message: 'Priorité modifiée avec succès', priority });
|
||||
|
||||
@@ -88,7 +88,7 @@ router.put('/feeds/:id', requireAdmin, async (req, res) => {
|
||||
|
||||
await runQuery(
|
||||
'UPDATE rss_feeds SET enabled = $1 WHERE id = $2',
|
||||
[enabled ? 1 : 0, req.params.id]
|
||||
[enabled, req.params.id] // BOOLEAN instead of 0/1
|
||||
);
|
||||
|
||||
logger.info(`Flux ${enabled ? 'activé' : 'désactivé'}: ${req.params.id}`);
|
||||
|
||||
@@ -90,7 +90,7 @@ router.put('/feeds/:id', requireAdmin, async (req, res) => {
|
||||
|
||||
await runQuery(
|
||||
'UPDATE rss_feeds SET enabled = $1 WHERE id = $2',
|
||||
[enabled ? 1 : 0, req.params.id]
|
||||
[enabled, req.params.id] // BOOLEAN instead of 0/1
|
||||
);
|
||||
|
||||
logger.info(`Flux ${enabled ? 'activé' : 'désactivé'}: ${req.params.id}`);
|
||||
|
||||
@@ -140,17 +140,17 @@ router.put('/:id',
|
||||
if (completed !== undefined) {
|
||||
paramCount++;
|
||||
updates.push(`completed = $${paramCount}`);
|
||||
params.push(completed ? 1 : 0);
|
||||
params.push(completed); // BOOLEAN instead of 0/1
|
||||
}
|
||||
if (priority !== undefined) {
|
||||
paramCount++;
|
||||
updates.push(`priority = $${paramCount}`);
|
||||
params.push(priority ? 1 : 0);
|
||||
params.push(priority); // BOOLEAN instead of 0/1
|
||||
}
|
||||
if (in_progress !== undefined) {
|
||||
paramCount++;
|
||||
updates.push(`in_progress = $${paramCount}`);
|
||||
params.push(in_progress ? 1 : 0);
|
||||
params.push(in_progress); // BOOLEAN instead of 0/1
|
||||
}
|
||||
|
||||
if (updates.length > 0) {
|
||||
@@ -179,12 +179,12 @@ router.patch('/:id/toggle', async (req, res) => {
|
||||
return res.status(404).json({ error: 'Todo non trouvé' });
|
||||
}
|
||||
|
||||
const newCompleted = todo.completed ? 0 : 1;
|
||||
const newCompleted = !todo.completed; // BOOLEAN instead of 0/1
|
||||
await runQuery('UPDATE global_todos SET completed = $1 WHERE id = $2', [newCompleted, req.params.id]);
|
||||
|
||||
logger.info(`Todo global ${newCompleted ? 'complété' : 'réouvert'} (ID: ${req.params.id}) par ${req.user.username}`);
|
||||
|
||||
res.json({ message: 'Todo modifié avec succès', completed: newCompleted === 1 });
|
||||
res.json({ message: 'Todo modifié avec succès', completed: newCompleted });
|
||||
} catch (error) {
|
||||
logger.error('Erreur lors du toggle du todo:', error);
|
||||
res.status(500).json({ error: 'Erreur serveur' });
|
||||
@@ -204,12 +204,12 @@ router.patch('/:id/priority', async (req, res) => {
|
||||
return res.status(404).json({ error: 'Todo non trouvé' });
|
||||
}
|
||||
|
||||
const newPriority = todo.priority ? 0 : 1;
|
||||
const newPriority = !todo.priority; // BOOLEAN instead of 0/1
|
||||
await runQuery('UPDATE global_todos SET priority = $1 WHERE id = $2', [newPriority, req.params.id]);
|
||||
|
||||
logger.info(`Todo global ${newPriority ? 'marqué prioritaire' : 'démarqué prioritaire'} (ID: ${req.params.id}) par ${req.user.username}`);
|
||||
|
||||
res.json({ message: 'Priorité modifiée avec succès', priority: newPriority === 1 });
|
||||
res.json({ message: 'Priorité modifiée avec succès', priority: newPriority });
|
||||
} catch (priorityError) {
|
||||
// Si le champ priority n'existe pas encore, retourner un message d'erreur explicite
|
||||
if (priorityError.message && priorityError.message.includes('priority')) {
|
||||
@@ -240,12 +240,12 @@ router.patch('/:id/in-progress', async (req, res) => {
|
||||
return res.status(404).json({ error: 'Todo non trouvé' });
|
||||
}
|
||||
|
||||
const newInProgress = todo.in_progress ? 0 : 1;
|
||||
const newInProgress = !todo.in_progress; // BOOLEAN instead of 0/1
|
||||
await runQuery('UPDATE global_todos SET in_progress = $1 WHERE id = $2', [newInProgress, req.params.id]);
|
||||
|
||||
logger.info(`Todo global ${newInProgress ? 'marqué en cours' : 'démarqué en cours'} (ID: ${req.params.id}) par ${req.user.username}`);
|
||||
|
||||
res.json({ message: 'Statut en cours modifié avec succès', in_progress: newInProgress === 1 });
|
||||
res.json({ message: 'Statut en cours modifié avec succès', in_progress: newInProgress });
|
||||
} catch (inProgressError) {
|
||||
// Si le champ in_progress n'existe pas encore
|
||||
if (inProgressError.message && inProgressError.message.includes('in_progress')) {
|
||||
|
||||
@@ -56,12 +56,12 @@ router.post('/',
|
||||
// Hasher le mot de passe
|
||||
const passwordHash = await bcrypt.hash(password, 12);
|
||||
|
||||
logger.info(`[CREATE USER] Début création - username: "${username}", is_admin: ${is_admin ? 1 : 0}`);
|
||||
logger.info(`[CREATE USER] Début création - username: "${username}", is_admin: ${is_admin || false}`);
|
||||
|
||||
// Créer l'utilisateur
|
||||
const result = await runQuery(
|
||||
'INSERT INTO users (username, password_hash, is_admin) VALUES ($1, $2, $3) RETURNING *',
|
||||
[username, passwordHash, is_admin ? 1 : 0]
|
||||
[username, passwordHash, is_admin || false] // BOOLEAN instead of 0/1
|
||||
);
|
||||
|
||||
logger.info(`[CREATE USER] Utilisateur créé avec succès - ID: ${result.id}, username: "${username}"`);
|
||||
@@ -111,7 +111,7 @@ router.put('/:id',
|
||||
|
||||
// Mettre à jour le statut admin si fourni
|
||||
if (typeof is_admin !== 'undefined') {
|
||||
await runQuery('UPDATE users SET is_admin = $1 WHERE id = $2', [is_admin ? 1 : 0, userId]);
|
||||
await runQuery('UPDATE users SET is_admin = $1 WHERE id = $2', [is_admin, userId]); // BOOLEAN instead of 0/1
|
||||
}
|
||||
|
||||
logger.info(`Utilisateur modifié: ${user.username} (ID: ${userId})`);
|
||||
|
||||
Reference in new issue
Block a user