Replace notifications with activity feed
This commit is contained in:
@@ -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',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user