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