const express = require('express'); const router = express.Router(); const db = global.db; router.post('/', async (req, res) => { const {serverId, serverStartTime, shutdownReason, shutdownTime, duration, totalPlayers } = req.body; if (!serverId || !serverStartTime || !shutdownReason || !shutdownTime || duration === undefined || totalPlayers === undefined) { return res.status(400).json({ error: 'Missing required fields' }); } db.run('UPDATE analytics SET endTime = ?, shutdownReason = ?, serverDuration = ?, allPlayers = ? WHERE id = ?', [shutdownTime, shutdownReason, duration, JSON.stringify(totalPlayers), serverId], function(err) { if (err) { console.error('Failed to record shutdown data', err); return res.status(500).json({ error: 'Database error' }); } return res.status(200).json({ message: 'Shutdown data recorded' }); } ); }); module.exports = router;