From ff1fe0ff92d1d60f66817d77c650fce4eac101df Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 2 Aug 2025 08:32:22 -0400 Subject: [PATCH] testing --- public/index.html | 7 +++++++ server.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/public/index.html b/public/index.html index 0586c2f..74dbfdb 100644 --- a/public/index.html +++ b/public/index.html @@ -272,6 +272,13 @@ // --- Initializer --- signOutBtn.addEventListener('click', () => handleSignOut()); + + document.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'visible') { + console.log("Tab is visible, refreshing UI."); + updateUI(); + } +}); updateUI(); diff --git a/server.js b/server.js index a7dbbaf..fe014b2 100644 --- a/server.js +++ b/server.js @@ -202,7 +202,37 @@ function setupRoutes() { res.status(500).json({ message: "Server error during cleanup." }); } }); + app.get('/api/admin/logs', authenticateToken, requireRole('admin'), async (req, res) => { + try { + const rows = await db.all("SELECT * FROM time_entries ORDER BY punch_in_time DESC"); + res.json(rows); + } catch { + res.status(500).json({ message: "Server error fetching logs." }); + } +}); +// THIS IS THE NEW/FIXED ROUTE +app.put('/api/admin/logs/:id', authenticateToken, requireRole('admin'), async (req, res) => { + try { + const { id } = req.params; + const { punch_in_time, punch_out_time } = req.body; + + // **THE FIX IS HERE** + // Determine the correct status based on the punch_out_time. + const status = punch_out_time ? 'out' : 'in'; + + await db.run( + `UPDATE time_entries + SET punch_in_time = ?, punch_out_time = ?, status = ? + WHERE id = ?`, + [punch_in_time, punch_out_time, status, id] + ); + res.json({ message: 'Entry updated successfully.' }); + } catch (err) { + console.error("Error updating log:", err); + res.status(500).json({ message: 'Failed to update entry.' }); + } +}); // Other admin routes (logs, users, roles, etc.) stay the same... }