From 979e9724e002f0b180a8314fa065eec50fcc66bd Mon Sep 17 00:00:00 2001 From: jason Date: Sat, 7 Mar 2026 22:01:35 -0600 Subject: [PATCH] fix: score endpoint now returns total_violations and negated_count The /api/employees/:id/score endpoint previously only returned data from the active_cpas_scores view (active_points + violation_count for the 90-day window). The EmployeeModal score cards reference total_violations and negated_count which were undefined, causing blank displays. Now queries the violations table directly for all-time totals alongside the rolling 90-day active data. --- server.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 59ed7d3..f4c59cc 100755 --- a/server.js +++ b/server.js @@ -128,10 +128,29 @@ app.patch('/api/employees/:id/notes', (req, res) => { res.json({ id, notes: newNotes }); }); -// Employee score (current snapshot) +// Employee score (current snapshot) — includes total violations + negated count app.get('/api/employees/:id/score', (req, res) => { - const row = db.prepare('SELECT * FROM active_cpas_scores WHERE employee_id = ?').get(req.params.id); - res.json(row || { employee_id: req.params.id, active_points: 0, violation_count: 0 }); + const empId = req.params.id; + + // Active points from the 90-day rolling view + const active = db.prepare('SELECT * FROM active_cpas_scores WHERE employee_id = ?').get(empId); + + // Total violations (all time) and negated count + const totals = db.prepare(` + SELECT + COUNT(*) AS total_violations, + COALESCE(SUM(negated), 0) AS negated_count + FROM violations + WHERE employee_id = ? + `).get(empId); + + res.json({ + employee_id: empId, + active_points: active ? active.active_points : 0, + violation_count: active ? active.violation_count : 0, + total_violations: totals ? totals.total_violations : 0, + negated_count: totals ? totals.negated_count : 0, + }); }); // ── Expiration Timeline ────────────────────────────────────────────────────── -- 2.49.1