Replace notifications with activity feed

This commit is contained in:
Cauê Faleiros
2026-05-29 14:34:40 -03:00
parent 0f322e9c85
commit e64654c820
14 changed files with 154 additions and 313 deletions

View File

@@ -4,6 +4,7 @@ const jwt = require('jsonwebtoken');
const crypto = require('crypto');
const { hashSecret, maskSecret } = require('../utils/security');
const { requireRole } = require('../middleware/auth');
const { recordActivity } = require('../services/activityService');
const createAuthRouter = ({ pool, transporter, getBaseUrl, jwtSecret }) => {
const router = express.Router();
@@ -229,19 +230,25 @@ const createAuthRouter = ({ pool, transporter, getBaseUrl, jwtSecret }) => {
[user.tenant_id, user.id]
);
for (const n of notifiable) {
await pool.query(
'INSERT INTO notifications (id, user_id, type, title, message, link) VALUES (?, ?, ?, ?, ?, ?)',
[crypto.randomUUID(), n.id, 'info', 'Novo Membro Ativo', `${name} concluiu o cadastro e já pode acessar o sistema.`, `/users/${user.id}`]
);
await recordActivity(pool, {
userId: n.id,
type: 'info',
title: 'Novo Membro Ativo',
message: `${name} concluiu o cadastro e já pode acessar o sistema.`,
link: `/users/${user.id}`,
});
}
if (user.role === 'admin') {
const [superAdmins] = await pool.query("SELECT id FROM users WHERE role = 'super_admin'");
for (const sa of superAdmins) {
await pool.query(
'INSERT INTO notifications (id, user_id, type, title, message, link) VALUES (?, ?, ?, ?, ?, ?)',
[crypto.randomUUID(), sa.id, 'success', 'Admin Ativo', `O admin ${name} da organização configurou sua conta.`, `/super-admin`]
);
await recordActivity(pool, {
userId: sa.id,
type: 'success',
title: 'Admin Ativo',
message: `O admin ${name} da organização configurou sua conta.`,
link: '/super-admin',
});
}
}
}