fix(webapp): persist motion alerts in activity feed
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user