Files
betterhuman/backend/dist/routes/notifications.js
T

48 lines
1.7 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("express");
const prisma_1 = __importDefault(require("../lib/prisma"));
const auth_1 = require("../middleware/auth");
const router = (0, express_1.Router)();
// GET /notifications
router.get('/', auth_1.requireAuth, async (req, res) => {
try {
const notifications = await prisma_1.default.notification.findMany({
where: { userId: req.user.id },
orderBy: [{ isRead: 'asc' }, { createdAt: 'desc' }],
take: 50,
});
return res.json(notifications);
}
catch (err) {
return res.status(500).json({ error: 'Internal server error' });
}
});
// PATCH /notifications/:id/read
router.patch('/:id/read', auth_1.requireAuth, async (req, res) => {
try {
await prisma_1.default.notification.update({ where: { id: req.params.id }, data: { isRead: true } });
return res.json({ message: 'Marked as read' });
}
catch (err) {
return res.status(500).json({ error: 'Internal server error' });
}
});
// POST /notifications/read-all
router.post('/read-all', auth_1.requireAuth, async (req, res) => {
try {
await prisma_1.default.notification.updateMany({
where: { userId: req.user.id, isRead: false },
data: { isRead: true },
});
return res.json({ message: 'All marked as read' });
}
catch (err) {
return res.status(500).json({ error: 'Internal server error' });
}
});
exports.default = router;
//# sourceMappingURL=notifications.js.map