calendar download, date input validate, nc talk notification
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
import pool from '../config/database';
|
||||
import notificationService from '../services/notification.service';
|
||||
import nextcloudService from '../services/nextcloud.service';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
const INTERVAL_MS = 15 * 60 * 1000; // 15 minutes
|
||||
@@ -28,6 +29,7 @@ export async function runNotificationGeneration(): Promise<void> {
|
||||
await generateAtemschutzNotifications();
|
||||
await generateVehicleNotifications();
|
||||
await generateEquipmentNotifications();
|
||||
await generateNextcloudTalkNotifications();
|
||||
await notificationService.deleteOldRead();
|
||||
} catch (error) {
|
||||
logger.error('NotificationGenerationJob: unexpected error', {
|
||||
@@ -234,6 +236,56 @@ async function generateEquipmentNotifications(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 4. Nextcloud Talk unread messages → per-user notifications
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function generateNextcloudTalkNotifications(): Promise<void> {
|
||||
const usersResult = await pool.query(`
|
||||
SELECT id, nextcloud_login_name, nextcloud_app_password
|
||||
FROM users
|
||||
WHERE is_active = TRUE
|
||||
AND nextcloud_login_name IS NOT NULL
|
||||
AND nextcloud_app_password IS NOT NULL
|
||||
`);
|
||||
|
||||
for (const user of usersResult.rows) {
|
||||
try {
|
||||
const { conversations } = await nextcloudService.getConversations(
|
||||
user.nextcloud_login_name,
|
||||
user.nextcloud_app_password,
|
||||
);
|
||||
|
||||
for (const conv of conversations) {
|
||||
if (conv.unreadMessages <= 0) continue;
|
||||
await notificationService.createNotification({
|
||||
user_id: user.id,
|
||||
typ: 'nextcloud_talk',
|
||||
titel: conv.displayName,
|
||||
nachricht: `${conv.unreadMessages} ungelesene Nachrichten`,
|
||||
schwere: 'info',
|
||||
link: conv.url,
|
||||
quell_id: conv.token,
|
||||
quell_typ: 'nextcloud_talk',
|
||||
});
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error?.code === 'NEXTCLOUD_AUTH_INVALID') {
|
||||
await pool.query(
|
||||
`UPDATE users SET nextcloud_login_name = NULL, nextcloud_app_password = NULL WHERE id = $1`,
|
||||
[user.id],
|
||||
);
|
||||
logger.warn('NotificationGenerationJob: cleared invalid Nextcloud credentials', { userId: user.id });
|
||||
continue;
|
||||
}
|
||||
logger.error('NotificationGenerationJob: generateNextcloudTalkNotifications failed for user', {
|
||||
userId: user.id,
|
||||
error,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Job lifecycle
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user