fix: resolve notification ui bugs, audio playback, and team deletion
- Fixed audio playback by rendering a hidden audio tag to comply with browser policies. - Renamed DELETE /notifications to /notifications/clear-all to prevent route conflicts. - Notifications badge now clears automatically when the tray is opened. - Translated notification types to Portuguese (SUCESSO, AVISO, ERRO, INFO). - Implemented team deletion functionality for Admins.
This commit is contained in:
@@ -551,7 +551,7 @@ apiRouter.delete('/notifications/:id', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
apiRouter.delete('/notifications', async (req, res) => {
|
||||
apiRouter.delete('/notifications/clear-all', async (req, res) => {
|
||||
try {
|
||||
await pool.query(
|
||||
'DELETE FROM notifications WHERE user_id = ?',
|
||||
@@ -918,6 +918,25 @@ apiRouter.put('/teams/:id', requireRole(['admin', 'owner', 'super_admin']), asyn
|
||||
}
|
||||
});
|
||||
|
||||
apiRouter.delete('/teams/:id', requireRole(['admin', 'owner', 'super_admin']), async (req, res) => {
|
||||
try {
|
||||
const [existing] = await pool.query('SELECT tenant_id FROM teams WHERE id = ?', [req.params.id]);
|
||||
if (existing.length === 0) return res.status(404).json({ error: 'Not found' });
|
||||
if (req.user.role !== 'super_admin' && existing[0].tenant_id !== req.user.tenant_id) {
|
||||
return res.status(403).json({ error: 'Acesso negado.' });
|
||||
}
|
||||
|
||||
// Set users team_id to NULL to prevent orphan foreign key issues if constrained
|
||||
await pool.query('UPDATE users SET team_id = NULL WHERE team_id = ?', [req.params.id]);
|
||||
await pool.query('DELETE FROM teams WHERE id = ?', [req.params.id]);
|
||||
|
||||
res.json({ message: 'Team deleted successfully.' });
|
||||
} catch (error) {
|
||||
console.error('Delete team error:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
apiRouter.post('/tenants', requireRole(['super_admin']), async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user