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 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<string, WebSocket> = new Map();
// Connected clients (using any to avoid ws type issues)
const clients: Map<string, any> = 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);
});

View file

@ -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
}
});

View file

@ -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()
}
});