fix: TypeScript errors in websocket plugin and Prisma calls
This commit is contained in:
parent
5c86b98628
commit
54531a79d5
3 changed files with 8 additions and 35 deletions
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue