- Full-stack: React 18 + Express + SQLite - Drag-and-drop kanban boards with @hello-pangea/dnd - Google App Password email integration (SMTP + IMAP) - Inbound email: create cards by sending emails - Reply-to-card: email replies become comments - Admin/user management with role-based access - Setup wizard: email config → admin creation - Checklists, time tracking, priorities, labels, due dates - Real-time notifications with activity feed - Beautiful HTML email templates
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
import { Router } from 'express';
|
|
import db from '../db.js';
|
|
import { authMiddleware } from '../middleware/auth.js';
|
|
|
|
const router = Router();
|
|
router.use(authMiddleware);
|
|
|
|
router.get('/', (req, res) => {
|
|
const notifs = db.prepare(`
|
|
SELECT n.* FROM notifications n
|
|
WHERE n.user_id = ?
|
|
ORDER BY n.is_read ASC, n.created_at DESC
|
|
LIMIT 50
|
|
`).all(req.user.id);
|
|
const unread = db.prepare('SELECT COUNT(*) as c FROM notifications WHERE user_id = ? AND is_read = 0').get(req.user.id).c;
|
|
res.json({ notifications: notifs, unread });
|
|
});
|
|
|
|
router.put('/:id/read', (req, res) => {
|
|
db.prepare('UPDATE notifications SET is_read = 1 WHERE id = ? AND user_id = ?').run(req.params.id, req.user.id);
|
|
res.json({ success: true });
|
|
});
|
|
|
|
router.put('/read-all', (req, res) => {
|
|
db.prepare('UPDATE notifications SET is_read = 1 WHERE user_id = ?').run(req.user.id);
|
|
res.json({ success: true });
|
|
});
|
|
|
|
router.delete('/:id', (req, res) => {
|
|
db.prepare('DELETE FROM notifications WHERE id = ? AND user_id = ?').run(req.params.id, req.user.id);
|
|
res.json({ success: true });
|
|
});
|
|
|
|
export default router;
|