31 lines
676 B
JavaScript
31 lines
676 B
JavaScript
const express = require('express');
|
|
|
|
const createActivityRouter = ({ pool }) => {
|
|
const router = express.Router();
|
|
|
|
const listActivity = async (req, res) => {
|
|
try {
|
|
const [rows] = await pool.query(
|
|
`SELECT id, type, title, message, link, created_at
|
|
FROM notifications
|
|
WHERE user_id = ?
|
|
ORDER BY created_at DESC
|
|
LIMIT 50`,
|
|
[req.user.id]
|
|
);
|
|
res.json(rows);
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
};
|
|
|
|
router.get('/activity', listActivity);
|
|
router.get('/notifications', listActivity);
|
|
|
|
return router;
|
|
};
|
|
|
|
module.exports = {
|
|
createActivityRouter,
|
|
};
|