forked from Deen-Bridge/dnb-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotificationRoutes.js
More file actions
42 lines (33 loc) · 1.24 KB
/
Copy pathnotificationRoutes.js
File metadata and controls
42 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import express from "express";
import { protect } from "../middlewares/authMiddleware.js";
import {
sseNotifications,
getUserNotifications,
markNotificationAsRead,
markAllNotificationsAsRead,
deleteNotification,
getNotificationSettings,
} from "../controllers/notificationController.js";
const router = express.Router();
// Accept token from query param (EventSource can't set custom headers)
const sseAuth = async (req, res, next) => {
const token = req.query.token;
if (!token) {
return res.status(401).json({ success: false, message: "No token, authorization denied" });
}
req.headers.authorization = `Bearer ${token}`;
protect(req, res, next);
};
// SSE endpoint for real-time notifications (uses query-param auth)
router.get("/sse", sseAuth, sseNotifications);
// Get user notifications
router.get("/", protect, getUserNotifications);
// Mark notification as read
router.put("/:notificationId/read", protect, markNotificationAsRead);
// Mark all notifications as read
router.put("/mark-all-read", protect, markAllNotificationsAsRead);
// Delete notification
router.delete("/:notificationId", protect,deleteNotification);
// Get notification settings
router.get("/settings", protect, getNotificationSettings);
export default router;