fix: TypeScript errors in websocket plugin and Prisma calls
Some checks are pending
Test / backend-test (push) Waiting to run
Test / frontend-test (push) Waiting to run

This commit is contained in:
fullsizemalt 2026-01-05 20:25:22 -08:00
parent 5c86b98628
commit 54531a79d5
3 changed files with 8 additions and 35 deletions

View file

@ -6,7 +6,6 @@
import { FastifyInstance } from 'fastify'; import { FastifyInstance } from 'fastify';
import websocket from '@fastify/websocket'; import websocket from '@fastify/websocket';
import type { WebSocket } from 'ws';
interface AlertMessage { interface AlertMessage {
type: 'ALERT' | 'READING' | 'HEARTBEAT'; type: 'ALERT' | 'READING' | 'HEARTBEAT';
@ -14,8 +13,8 @@ interface AlertMessage {
timestamp: string; timestamp: string;
} }
// Connected clients // Connected clients (using any to avoid ws type issues)
const clients: Map<string, WebSocket> = new Map(); const clients: Map<string, any> = new Map();
export async function websocketPlugin(fastify: FastifyInstance) { export async function websocketPlugin(fastify: FastifyInstance) {
await fastify.register(websocket); await fastify.register(websocket);
@ -36,7 +35,7 @@ export async function websocketPlugin(fastify: FastifyInstance) {
timestamp: new Date().toISOString() timestamp: new Date().toISOString()
})); }));
socket.on('message', (message) => { socket.on('message', (message: Buffer) => {
try { try {
const data = JSON.parse(message.toString()); const data = JSON.parse(message.toString());
@ -54,7 +53,7 @@ export async function websocketPlugin(fastify: FastifyInstance) {
fastify.log.info(`WebSocket client disconnected: ${clientId}`); fastify.log.info(`WebSocket client disconnected: ${clientId}`);
}); });
socket.on('error', (error) => { socket.on('error', (error: Error) => {
fastify.log.error(`WebSocket error for ${clientId}:`, error); fastify.log.error(`WebSocket error for ${clientId}:`, error);
clients.delete(clientId); clients.delete(clientId);
}); });

View file

@ -465,14 +465,7 @@ export async function environmentRoutes(fastify: FastifyInstance) {
sensorId: r.sensorId || 'edge-default', sensorId: r.sensorId || 'edge-default',
value: r.temperature, // Primary value is temperature value: r.temperature, // Primary value is temperature
unit: '°F', unit: '°F',
timestamp: new Date(r.timestamp), timestamp: new Date(r.timestamp)
metadata: {
humidity: r.humidity,
dewpoint: r.dewpoint,
vpd: r.vpd,
roomId: r.roomId,
facilityId
}
} }
}) })
) )
@ -570,14 +563,7 @@ export async function environmentRoutes(fastify: FastifyInstance) {
severity: data.alertType.includes('HIGH') ? 'WARNING' : 'INFO', severity: data.alertType.includes('HIGH') ? 'WARNING' : 'INFO',
message: `${data.sensorName}: ${data.alertType.replace('_', ' ')} (${data.currentValue} vs threshold ${data.threshold})`, message: `${data.sensorName}: ${data.alertType.replace('_', ' ')} (${data.currentValue} vs threshold ${data.threshold})`,
value: data.currentValue, value: data.currentValue,
threshold: data.threshold, threshold: data.threshold
metadata: {
facilityId: data.facilityId,
edgeId: data.edgeId,
sensorId: data.sensorId,
sensorName: data.sensorName,
edgeTimestamp: data.timestamp
}
} }
}); });

View file

@ -37,13 +37,7 @@ async function generateDemoAlert() {
severity: 'WARNING', severity: 'WARNING',
message: `${sensor.name}: ${alertConfig.metric} ${alertConfig.type.includes('HIGH') ? 'above' : 'below'} threshold (${value.toFixed(1)} vs ${threshold.toFixed(1)})`, message: `${sensor.name}: ${alertConfig.metric} ${alertConfig.type.includes('HIGH') ? 'above' : 'below'} threshold (${value.toFixed(1)} vs ${threshold.toFixed(1)})`,
value: value, value: value,
threshold: threshold, threshold: threshold
metadata: {
sensorId: sensor.id,
sensorName: sensor.name,
roomId: sensor.roomId,
isDemo: true
}
} }
}); });
@ -64,13 +58,7 @@ async function generateDemoReading() {
sensorId: sensor.id, sensorId: sensor.id,
value: temperature, value: temperature,
unit: '°F', unit: '°F',
timestamp: new Date(), timestamp: new Date()
metadata: {
humidity,
vpd,
sensorName: sensor.name,
isDemo: true
}
} }
}); });