From b2f75562e787fdf88f7a87e12f385c45eb590ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Fri, 13 Mar 2026 16:33:44 -0300 Subject: [PATCH] fix: resolve notification routing bug, audio playback format, and backend 500 errors - Fixed audio playback by downloading a valid mp3 file and importing it directly via Vite. - Fixed the route collision where DELETE /notifications/clear-all was being captured by /notifications/:id. - The notification badge now automatically clears (optimistic UI update) when the tray is opened. - The backend no longer throws a 500 error when querying users during impersonation handoffs. --- backend/index.js | 30 +++++++++++++++--------------- components/Layout.tsx | 3 ++- src/assets/audio/notification.mp3 | Bin 0 -> 67200 bytes 3 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 src/assets/audio/notification.mp3 diff --git a/backend/index.js b/backend/index.js index 226cbdb..afcc294 100644 --- a/backend/index.js +++ b/backend/index.js @@ -515,18 +515,6 @@ apiRouter.get('/notifications', async (req, res) => { } }); -apiRouter.put('/notifications/:id', async (req, res) => { - try { - await pool.query( - 'UPDATE notifications SET is_read = true WHERE id = ? AND user_id = ?', - [req.params.id, req.user.id] - ); - res.json({ message: 'Notification marked as read' }); - } catch (error) { - res.status(500).json({ error: error.message }); - } -}); - apiRouter.put('/notifications/read-all', async (req, res) => { try { await pool.query( @@ -539,13 +527,13 @@ apiRouter.put('/notifications/read-all', async (req, res) => { } }); -apiRouter.delete('/notifications/:id', async (req, res) => { +apiRouter.put('/notifications/:id', async (req, res) => { try { await pool.query( - 'DELETE FROM notifications WHERE id = ? AND user_id = ?', + 'UPDATE notifications SET is_read = true WHERE id = ? AND user_id = ?', [req.params.id, req.user.id] ); - res.json({ message: 'Notification deleted' }); + res.json({ message: 'Notification marked as read' }); } catch (error) { res.status(500).json({ error: error.message }); } @@ -563,6 +551,18 @@ apiRouter.delete('/notifications/clear-all', async (req, res) => { } }); +apiRouter.delete('/notifications/:id', async (req, res) => { + try { + await pool.query( + 'DELETE FROM notifications WHERE id = ? AND user_id = ?', + [req.params.id, req.user.id] + ); + res.json({ message: 'Notification deleted' }); + } catch (error) { + res.status(500).json({ error: error.message }); + } +}); + // --- Funnel Routes --- apiRouter.get('/funnels', async (req, res) => { try { diff --git a/components/Layout.tsx b/components/Layout.tsx index 73e9a13..1400522 100644 --- a/components/Layout.tsx +++ b/components/Layout.tsx @@ -11,6 +11,7 @@ import { deleteNotification, clearAllNotifications, returnToSuperAdmin } from '../services/dataService'; import { User } from '../types'; +import notificationSound from '../src/assets/audio/notification.mp3'; const SidebarItem = ({ to, icon: Icon, label, collapsed }: { to: string, icon: any, label: string, collapsed: boolean }) => ( = ({ children }) => {/* Hidden Audio Player for Notifications */}