From 54531a79d5af9beeaf8f66a45b12e3f077abec07 Mon Sep 17 00:00:00 2001 From: fullsizemalt <106900403+fullsizemalt@users.noreply.github.com> Date: Mon, 5 Jan 2026 20:25:22 -0800 Subject: [PATCH] fix: TypeScript errors in websocket plugin and Prisma calls --- backend/src/plugins/websocket.ts | 9 ++++----- backend/src/routes/environment.routes.ts | 18 ++---------------- backend/src/scripts/demo-alerts.ts | 16 ++-------------- 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/backend/src/plugins/websocket.ts b/backend/src/plugins/websocket.ts index ba1c6b0..1cb2d80 100644 --- a/backend/src/plugins/websocket.ts +++ b/backend/src/plugins/websocket.ts @@ -6,7 +6,6 @@ import { FastifyInstance } from 'fastify'; import websocket from '@fastify/websocket'; -import type { WebSocket } from 'ws'; interface AlertMessage { type: 'ALERT' | 'READING' | 'HEARTBEAT'; @@ -14,8 +13,8 @@ interface AlertMessage { timestamp: string; } -// Connected clients -const clients: Map = new Map(); +// Connected clients (using any to avoid ws type issues) +const clients: Map = new Map(); export async function websocketPlugin(fastify: FastifyInstance) { await fastify.register(websocket); @@ -36,7 +35,7 @@ export async function websocketPlugin(fastify: FastifyInstance) { timestamp: new Date().toISOString() })); - socket.on('message', (message) => { + socket.on('message', (message: Buffer) => { try { const data = JSON.parse(message.toString()); @@ -54,7 +53,7 @@ export async function websocketPlugin(fastify: FastifyInstance) { fastify.log.info(`WebSocket client disconnected: ${clientId}`); }); - socket.on('error', (error) => { + socket.on('error', (error: Error) => { fastify.log.error(`WebSocket error for ${clientId}:`, error); clients.delete(clientId); }); diff --git a/backend/src/routes/environment.routes.ts b/backend/src/routes/environment.routes.ts index dbba15e..b7c8e8e 100644 --- a/backend/src/routes/environment.routes.ts +++ b/backend/src/routes/environment.routes.ts @@ -465,14 +465,7 @@ export async function environmentRoutes(fastify: FastifyInstance) { sensorId: r.sensorId || 'edge-default', value: r.temperature, // Primary value is temperature unit: '°F', - timestamp: new Date(r.timestamp), - metadata: { - humidity: r.humidity, - dewpoint: r.dewpoint, - vpd: r.vpd, - roomId: r.roomId, - facilityId - } + timestamp: new Date(r.timestamp) } }) ) @@ -570,14 +563,7 @@ export async function environmentRoutes(fastify: FastifyInstance) { severity: data.alertType.includes('HIGH') ? 'WARNING' : 'INFO', message: `${data.sensorName}: ${data.alertType.replace('_', ' ')} (${data.currentValue} vs threshold ${data.threshold})`, value: data.currentValue, - threshold: data.threshold, - metadata: { - facilityId: data.facilityId, - edgeId: data.edgeId, - sensorId: data.sensorId, - sensorName: data.sensorName, - edgeTimestamp: data.timestamp - } + threshold: data.threshold } }); diff --git a/backend/src/scripts/demo-alerts.ts b/backend/src/scripts/demo-alerts.ts index 7a4f05b..9d76e33 100644 --- a/backend/src/scripts/demo-alerts.ts +++ b/backend/src/scripts/demo-alerts.ts @@ -37,13 +37,7 @@ async function generateDemoAlert() { severity: 'WARNING', message: `${sensor.name}: ${alertConfig.metric} ${alertConfig.type.includes('HIGH') ? 'above' : 'below'} threshold (${value.toFixed(1)} vs ${threshold.toFixed(1)})`, value: value, - threshold: threshold, - metadata: { - sensorId: sensor.id, - sensorName: sensor.name, - roomId: sensor.roomId, - isDemo: true - } + threshold: threshold } }); @@ -64,13 +58,7 @@ async function generateDemoReading() { sensorId: sensor.id, value: temperature, unit: '°F', - timestamp: new Date(), - metadata: { - humidity, - vpd, - sensorName: sensor.name, - isDemo: true - } + timestamp: new Date() } });