Update server.js

This commit is contained in:
JoshBaneyCS 2025-04-23 08:32:02 +00:00
parent ab3065980e
commit 0463f6ffaa

View File

@ -109,8 +109,8 @@ app.use(express.static(path.join(__dirname, 'public')));
app.post('/api/readings', async (req, res) => { app.post('/api/readings', async (req, res) => {
try { try {
const { inbound, outbound } = req.body; const { inbound, outbound } = req.body;
const hiIn = computeHeatIndex(inbound.temperature, inbound.humidity); const hiIn = computeHeatIndex(inbound_temperature, inbound_humidity);
const hiOut = computeHeatIndex(outbound.temperature, outbound.humidity); const hiOut = computeHeatIndex(outbound_temperature, outbound_humidity);
// Shift & period logic // Shift & period logic
const { shift, shiftStart, key, estNow } = getShiftInfo(new Date()); const { shift, shiftStart, key, estNow } = getShiftInfo(new Date());
@ -123,13 +123,13 @@ app.post('/api/readings', async (req, res) => {
(dockDoor, timestamp, temperature, humidity, heatIndex) (dockDoor, timestamp, temperature, humidity, heatIndex)
VALUES (?, NOW(), ?, ?, ?) VALUES (?, NOW(), ?, ?, ?)
`; `;
await pool.execute(insertSQL, [inbound.dockDoor, inbound.temperature, inbound.humidity, hiIn]); await pool.execute(insertSQL, [inbound_dockDoor, inbound_temperature, inbound_humidity, hiIn]);
await pool.execute(insertSQL, [outbound.dockDoor, outbound.temperature, outbound.humidity, hiOut]); await pool.execute(insertSQL, [outbound_dockDoor, outbound_temperature, outbound_humidity, hiOut]);
// Broadcast to SSE clients (use UTC ISO for frontend) // Broadcast to SSE clients (use UTC ISO for frontend)
const isoNow = new Date().toISOString(); const isoNow = new Date().toISOString();
broadcast('new-reading', { dockDoor: inbound.dockDoor, timestamp: isoNow, ...inbound, heatIndex: hiIn }); broadcast('new-reading', { dockDoor: inbound_dockDoor, timestamp: isoNow, ...inbound, heatIndex: hiIn });
broadcast('new-reading', { dockDoor: outbound.dockDoor, timestamp: isoNow, ...outbound, heatIndex: hiOut }); broadcast('new-reading', { dockDoor: outbound_dockDoor, timestamp: isoNow, ...outbound, heatIndex: hiOut });
// Format EST timestamp for Slack // Format EST timestamp for Slack
const estString = estNow.toLocaleString('en-US', { const estString = estNow.toLocaleString('en-US', {
@ -143,14 +143,14 @@ app.post('/api/readings', async (req, res) => {
let slackText = let slackText =
`${shift} Shift ${period} temperature checks for ${estString} EST `${shift} Shift ${period} temperature checks for ${estString} EST
Inbound Dock Door: ${inbound.dockDoor} Inbound Dock Door: ${inbound_dockDoor}
Temp: ${inbound.temperature}°F Temp: ${inbound_temperature}°F
Humidity: ${inbound.humidity}% Humidity: ${inbound_humidity}%
Heat Index: ${hiIn} Heat Index: ${hiIn}
Outbound Dock Door: ${outbound.dockDoor} Outbound Dock Door: ${outbound_dockDoor}
Temp: ${outbound.temperature}°F Temp: ${outbound_temperature}°F
Humidity: ${outbound.humidity}% Humidity: ${outbound_humidity}%
Heat Index: ${hiOut}`; Heat Index: ${hiOut}`;
// Upload today's CSV and append URL // Upload today's CSV and append URL