fix(webapp): persist motion alerts in activity feed

This commit is contained in:
2026-04-06 13:30:00 +01:00
parent 3e0635fec3
commit 798fffa2a1
3 changed files with 89 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ import { Router } from 'express';
import { z } from 'zod';
import { db } from '../db/client';
import { deviceLinks, devices, events, notifications } from '../db/schema';
import { deviceLinks, devices, events, notificationDeliveries, notifications } from '../db/schema';
import { requireAuth } from '../middleware/auth';
import { requireDeviceAuth } from '../middleware/device-auth';
import { sendRealtimeToDevice } from '../realtime/gateway';
@@ -108,7 +108,23 @@ router.post('/motion/start', requireDeviceAuth, async (req, res) => {
sentAt: now,
});
if (!delivered) {
if (delivered) {
await db.insert(notificationDeliveries).values({
ownerUserId: deviceAuth.userId,
recipientDeviceId: link.clientDeviceId,
type: 'motion_detected',
payload: {
eventId: event.id,
cameraDeviceId: cameraDevice.id,
startedAt: event.startedAt.toISOString(),
},
status: 'delivered',
attempts: 1,
sentAt: now,
nextAttemptAt: now,
updatedAt: now,
});
} else {
await enqueuePushNotification({
ownerUserId: deviceAuth.userId,
recipientDeviceId: link.clientDeviceId,