resolve issues with new features

This commit is contained in:
Matthias Hochmeister
2026-03-12 16:42:21 +01:00
parent 5aa309b97a
commit 68586b01dc
19 changed files with 526 additions and 109 deletions

View File

@@ -13,6 +13,22 @@ class ConfigController {
}
}
async getPdfSettings(_req: Request, res: Response): Promise<void> {
try {
const header = await settingsService.get('pdf_header');
const footer = await settingsService.get('pdf_footer');
res.json({
success: true,
data: {
pdf_header: header?.value ?? '',
pdf_footer: footer?.value ?? '',
},
});
} catch {
res.json({ success: true, data: { pdf_header: '', pdf_footer: '' } });
}
}
async getExternalLinks(_req: Request, res: Response): Promise<void> {
const envLinks: Record<string, string> = {};
if (environment.nextcloudUrl) envLinks.nextcloud = environment.nextcloudUrl;

View File

@@ -67,6 +67,34 @@ class NotificationController {
res.status(500).json({ success: false, message: 'Notifications konnten nicht aktualisiert werden' });
}
}
/** POST /api/notifications/dismiss-by-type — marks all unread notifications of a given type as read. */
async dismissByType(req: Request, res: Response): Promise<void> {
try {
const { quellTyp } = req.body;
if (!quellTyp || typeof quellTyp !== 'string') {
res.status(400).json({ success: false, message: 'quellTyp ist erforderlich' });
return;
}
const userId = req.user!.id;
await notificationService.dismissByType(userId, quellTyp);
res.status(200).json({ success: true, message: 'Notifications als gelesen markiert' });
} catch (error) {
logger.error('NotificationController.dismissByType error', { error });
res.status(500).json({ success: false, message: 'Notifications konnten nicht aktualisiert werden' });
}
}
/** DELETE /api/notifications/read — deletes all read notifications for the authenticated user. */
async deleteAllRead(req: Request, res: Response): Promise<void> {
try {
const userId = req.user!.id;
await notificationService.deleteAllRead(userId);
res.status(200).json({ success: true, message: 'Gelesene Notifications gelöscht' });
} catch (error) {
logger.error('NotificationController.deleteAllRead error', { error });
res.status(500).json({ success: false, message: 'Gelesene Notifications konnten nicht gelöscht werden' });
}
}
}
export default new NotificationController();

View File

@@ -4,6 +4,7 @@ import { authenticate } from '../middleware/auth.middleware';
const router = Router();
router.get('/external-links', authenticate, configController.getExternalLinks.bind(configController));
router.get('/pdf-settings', authenticate, configController.getPdfSettings.bind(configController));
router.get('/service-mode', authenticate, configController.getServiceMode.bind(configController));
export default router;

View File

@@ -9,5 +9,7 @@ router.get('/', authenticate, notificationController.getNotific
router.get('/count', authenticate, notificationController.getUnreadCount.bind(notificationController));
router.patch('/:id/read', authenticate, notificationController.markAsRead.bind(notificationController));
router.post('/mark-all-read', authenticate, notificationController.markAllRead.bind(notificationController));
router.post('/dismiss-by-type', authenticate, notificationController.dismissByType.bind(notificationController));
router.delete('/read', authenticate, notificationController.deleteAllRead.bind(notificationController));
export default router;

View File

@@ -189,7 +189,7 @@ async function getPageById(id: number): Promise<BookStackPageDetail> {
html: page.html ?? '',
created_at: page.created_at,
updated_at: page.updated_at,
url: `${bookstack.url}/books/${page.book_slug || page.book_id}/page/${page.slug}`,
url: `${bookstack.url}/books/${page.book?.slug || page.book_slug || page.book_id}/page/${page.slug}`,
book: page.book,
createdBy: page.created_by,
updatedBy: page.updated_by,

View File

@@ -113,6 +113,33 @@ class NotificationService {
}
}
/** Marks all unread notifications of a given quell_typ as read for a user. */
async dismissByType(userId: string, quellTyp: string): Promise<void> {
try {
await pool.query(
`UPDATE notifications SET gelesen = TRUE, gelesen_am = NOW()
WHERE user_id = $1 AND quell_typ = $2 AND gelesen = FALSE`,
[userId, quellTyp]
);
} catch (error) {
logger.error('NotificationService.dismissByType failed', { error, userId, quellTyp });
throw new Error('Notifications konnten nicht als gelesen markiert werden');
}
}
/** Deletes all read notifications for a user. */
async deleteAllRead(userId: string): Promise<void> {
try {
await pool.query(
`DELETE FROM notifications WHERE user_id = $1 AND gelesen = TRUE`,
[userId]
);
} catch (error) {
logger.error('NotificationService.deleteAllRead failed', { error, userId });
throw new Error('Gelesene Notifications konnten nicht gelöscht werden');
}
}
/** Deletes read notifications older than 90 days for all users. */
async deleteOldRead(): Promise<void> {
try {