d594d00227
- Fixed theme not being reflected on gallery and admin login pages - Created GlobalThemeProvider to apply themes globally - Updated gallery and admin login pages to use dynamic CSS variables - Added complete translations for all admin sections in English and German: - Notifications management - Event view and creation - Photo upload functionality - Category management - Archive page view - Analytics dashboard - Branding and theme settings - System settings - CMS page management - Email configuration - Fixed admin photo management display issues - Fixed photo upload category assignment - Added password reset functionality for galleries - Improved error handling and user feedback 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
109 lines
3.1 KiB
JavaScript
109 lines
3.1 KiB
JavaScript
const express = require('express');
|
|
const { db, logActivity } = require('../database/db');
|
|
const { adminAuth } = require('../middleware/auth');
|
|
const router = express.Router();
|
|
|
|
// Get notifications (unread activity logs)
|
|
router.get('/', adminAuth, async (req, res) => {
|
|
try {
|
|
const { limit = 20, includeRead = false } = req.query;
|
|
|
|
let query = db('activity_logs')
|
|
.select(
|
|
'activity_logs.*',
|
|
'events.event_name'
|
|
)
|
|
.leftJoin('events', 'activity_logs.event_id', 'events.id')
|
|
.orderBy('activity_logs.created_at', 'desc')
|
|
.limit(parseInt(limit));
|
|
|
|
// By default, only show unread notifications
|
|
if (includeRead !== 'true') {
|
|
query = query.whereNull('activity_logs.read_at');
|
|
}
|
|
|
|
const notifications = await query;
|
|
|
|
// Format notifications
|
|
const formattedNotifications = notifications.map(notification => ({
|
|
id: notification.id,
|
|
type: notification.activity_type,
|
|
actorType: notification.actor_type,
|
|
actorName: notification.actor_name,
|
|
eventName: notification.event_name,
|
|
eventId: notification.event_id,
|
|
metadata: notification.metadata ? JSON.parse(notification.metadata) : {},
|
|
createdAt: notification.created_at,
|
|
readAt: notification.read_at,
|
|
isRead: !!notification.read_at
|
|
}));
|
|
|
|
// Get unread count
|
|
const unreadCount = await db('activity_logs')
|
|
.whereNull('read_at')
|
|
.count('id as count')
|
|
.first();
|
|
|
|
res.json({
|
|
notifications: formattedNotifications,
|
|
unreadCount: unreadCount.count || 0
|
|
});
|
|
} catch (error) {
|
|
console.error('Notifications fetch error:', error);
|
|
res.status(500).json({ error: 'Failed to fetch notifications' });
|
|
}
|
|
});
|
|
|
|
// Mark notification as read
|
|
router.put('/:id/read', adminAuth, async (req, res) => {
|
|
try {
|
|
const { id } = req.params;
|
|
|
|
await db('activity_logs')
|
|
.where('id', id)
|
|
.update({
|
|
read_at: new Date()
|
|
});
|
|
|
|
res.json({ message: 'Notification marked as read' });
|
|
} catch (error) {
|
|
console.error('Mark notification read error:', error);
|
|
res.status(500).json({ error: 'Failed to mark notification as read' });
|
|
}
|
|
});
|
|
|
|
// Mark all notifications as read
|
|
router.put('/read-all', adminAuth, async (req, res) => {
|
|
try {
|
|
await db('activity_logs')
|
|
.whereNull('read_at')
|
|
.update({
|
|
read_at: new Date()
|
|
});
|
|
|
|
res.json({ message: 'All notifications marked as read' });
|
|
} catch (error) {
|
|
console.error('Mark all notifications read error:', error);
|
|
res.status(500).json({ error: 'Failed to mark all notifications as read' });
|
|
}
|
|
});
|
|
|
|
// Delete old notifications (older than 30 days and read)
|
|
router.delete('/clear-old', adminAuth, async (req, res) => {
|
|
try {
|
|
const deletedCount = await db('activity_logs')
|
|
.whereNotNull('read_at')
|
|
.where('created_at', '<', db.raw("datetime('now', '-30 days')"))
|
|
.delete();
|
|
|
|
res.json({
|
|
message: 'Old notifications cleared',
|
|
deletedCount
|
|
});
|
|
} catch (error) {
|
|
console.error('Clear old notifications error:', error);
|
|
res.status(500).json({ error: 'Failed to clear old notifications' });
|
|
}
|
|
});
|
|
|
|
module.exports = router; |