diff --git a/backend/src/routes/notifications.ts b/backend/src/routes/notifications.ts index aba9cbc..6b36bb0 100644 --- a/backend/src/routes/notifications.ts +++ b/backend/src/routes/notifications.ts @@ -198,34 +198,51 @@ export default async function notificationsRoutes(server: FastifyInstance) { }) } - const result = await svc.trigger({ - tenantId, - userId: profile.userId, - eventType: "system.test_push", - title: "FEDEO Push ist aktiv", - message: "Diese Testbenachrichtigung wurde einmalig über das Mitarbeiterprofil ausgelöst.", - payload: { - link: "/", - icon: "/favicon.ico", - }, - channels: ["push"], - }) + const devices = await server.db + .select({ centralDeviceId: notificationMobilePushDevices.centralDeviceId }) + .from(notificationMobilePushDevices) + .where(and( + eq(notificationMobilePushDevices.tenantId, tenantId), + eq(notificationMobilePushDevices.userId, profile.userId), + isNull(notificationMobilePushDevices.disabledAt) + )) - if (result.created === 0) { + if (!devices.length) { return reply.code(409).send({ - error: "Pushnachrichten sind für diesen Mitarbeiter deaktiviert", - result, + error: "Für diesen Mitarbeiter ist kein aktives mobiles Push-Gerät registriert", }) } - if (!result.success || result.delivered === 0) { - return reply.code(424).send({ - error: "Die Pushnachricht konnte an kein aktives Gerät zugestellt werden", - result, + try { + const result = await pushServerClient.sendPush({ + idempotencyKey: `profile-mobile-test:${tenantId}:${profile.userId}:${Date.now()}`, + devices: devices.map((device) => device.centralDeviceId), + priority: "high", + ttlSeconds: 600, + notification: { + title: "FEDEO Push ist aktiv", + body: "Diese Testbenachrichtigung wurde einmalig über das Mitarbeiterprofil ausgelöst.", + }, + data: { + type: "system.test_mobile_push", + link: "/", + }, + }) + + if (result.accepted === 0) { + return reply.code(502).send({ + error: "Der zentrale Push-Server hat kein Gerät zur Zustellung angenommen", + result, + }) + } + + return result + } catch (error: any) { + server.log.error({ err: error, profileId, userId: profile.userId }, "Mitarbeiter-Test-Push fehlgeschlagen") + return reply.code(502).send({ + error: error?.message || "Der zentrale Push-Server konnte die Nachricht nicht annehmen", }) } - - return result }) server.post("/notifications/trigger", async (req, reply) => { diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts index ecfffb3..d573db0 100644 --- a/frontend/nuxt.config.ts +++ b/frontend/nuxt.config.ts @@ -119,9 +119,10 @@ export default defineNuxtConfig({ ] }, - /* WICHTIG FÜR SAFARI / iOS */ + // FEDEO wird serverseitig gerendert; es gibt daher keine vorab gecachte + // index.html, die Workbox als Navigations-Fallback verwenden könnte. workbox: { - navigateFallback: '/', + navigateFallback: null, }, devOptions: { diff --git a/frontend/pages/staff/profiles/[id].vue b/frontend/pages/staff/profiles/[id].vue index 9ddaea1..f621b8f 100644 --- a/frontend/pages/staff/profiles/[id].vue +++ b/frontend/pages/staff/profiles/[id].vue @@ -490,7 +490,7 @@ onMounted(async () => {

Push-Zustellung testen