Merge pull request 'fix: score endpoint now returns total_violations and negated_count' (#30) from feature/ack-signature-and-toasts into master
Reviewed-on: #30
This commit was merged in pull request #30.
This commit is contained in:
25
server.js
25
server.js
@@ -128,10 +128,29 @@ app.patch('/api/employees/:id/notes', (req, res) => {
|
|||||||
res.json({ id, notes: newNotes });
|
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) => {
|
app.get('/api/employees/:id/score', (req, res) => {
|
||||||
const row = db.prepare('SELECT * FROM active_cpas_scores WHERE employee_id = ?').get(req.params.id);
|
const empId = req.params.id;
|
||||||
res.json(row || { employee_id: req.params.id, active_points: 0, violation_count: 0 });
|
|
||||||
|
// 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 ──────────────────────────────────────────────────────
|
// ── Expiration Timeline ──────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user