feat: enhance notification management with new clearing functionalities
- Added functionality to clear all notifications and clear unread notifications for improved user control. - Updated NotificationBell component to support modal display for notifications, enhancing user experience. - Refactored notification handling to separate read and unread notifications, providing clearer organization. - Introduced new UI elements for managing notifications, including buttons for clearing notifications directly from the modal. - Improved backend mutations to handle notification deletion securely, ensuring users can only delete their own notifications.
This commit is contained in:
@@ -855,6 +855,54 @@ export const marcarTodasNotificacoesLidas = mutation({
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Deleta todas as notificações do usuário
|
||||
* SEGURANÇA: Usuário só pode deletar suas próprias notificações
|
||||
*/
|
||||
export const limparTodasNotificacoes = mutation({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
const usuarioAtual = await getUsuarioAutenticado(ctx);
|
||||
if (!usuarioAtual) throw new Error("Não autenticado");
|
||||
|
||||
const notificacoes = await ctx.db
|
||||
.query("notificacoes")
|
||||
.withIndex("by_usuario", (q) => q.eq("usuarioId", usuarioAtual._id))
|
||||
.collect();
|
||||
|
||||
for (const notificacao of notificacoes) {
|
||||
await ctx.db.delete(notificacao._id);
|
||||
}
|
||||
|
||||
return { excluidas: notificacoes.length };
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Deleta apenas as notificações não lidas do usuário
|
||||
* SEGURANÇA: Usuário só pode deletar suas próprias notificações
|
||||
*/
|
||||
export const limparNotificacoesNaoLidas = mutation({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
const usuarioAtual = await getUsuarioAutenticado(ctx);
|
||||
if (!usuarioAtual) throw new Error("Não autenticado");
|
||||
|
||||
const notificacoes = await ctx.db
|
||||
.query("notificacoes")
|
||||
.withIndex("by_usuario_lida", (q) =>
|
||||
q.eq("usuarioId", usuarioAtual._id).eq("lida", false)
|
||||
)
|
||||
.collect();
|
||||
|
||||
for (const notificacao of notificacoes) {
|
||||
await ctx.db.delete(notificacao._id);
|
||||
}
|
||||
|
||||
return { excluidas: notificacoes.length };
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Deleta uma mensagem (soft delete)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user