Add BU reassignment from/to detail view in anomaly banner

The AnomalyBanner BU reassignment row is now clickable, expanding to show
each affected finding with its host name and the team it moved from/to
(e.g. STEAM → PIES). The backend bu-changes endpoint now supports optional
since and limit query params to scope results to the relevant sync cycle.
This commit is contained in:
Jordan Ramos
2026-06-12 12:12:59 -06:00
parent 6465ac2a40
commit 356ce23462
2 changed files with 180 additions and 9 deletions

View File

@@ -1433,18 +1433,40 @@ function createIvantiFindingsRouter(db, requireAuth) {
/**
* GET /api/ivanti/findings/bu-changes
*
* Return all BU change events from ivanti_finding_bu_history.
* Return BU change events from ivanti_finding_bu_history.
* Accepts optional `since` to filter by date, or `limit` to cap the result count.
* If `since` is provided, returns all changes on or after that timestamp.
* If neither is provided, returns the most recent 200 rows (max 500).
*
* @returns {Object} 200 - { changes: Array<Object> }
* @query {string} [since] - ISO timestamp; return changes where detected_at >= this value
* @query {string} [limit] - Maximum number of rows to return (default 200, max 500); ignored when `since` is provided
* @returns {Object} 200 - { changes: Array<{ id, finding_id, finding_title, host_name, previous_bu, new_bu, detected_at }> }
* @returns {Object} 500 - { error: string } on database error
*/
router.get('/bu-changes', async (req, res) => {
try {
const { rows } = await pool.query(
`SELECT id, finding_id, finding_title, host_name, previous_bu, new_bu, detected_at
FROM ivanti_finding_bu_history
ORDER BY detected_at DESC`
);
const { since, limit } = req.query;
let rows;
if (since) {
const result = await pool.query(
`SELECT id, finding_id, finding_title, host_name, previous_bu, new_bu, detected_at
FROM ivanti_finding_bu_history
WHERE detected_at >= $1
ORDER BY detected_at DESC`,
[since]
);
rows = result.rows;
} else {
const maxRows = Math.min(parseInt(limit) || 200, 500);
const result = await pool.query(
`SELECT id, finding_id, finding_title, host_name, previous_bu, new_bu, detected_at
FROM ivanti_finding_bu_history
ORDER BY detected_at DESC
LIMIT $1`,
[maxRows]
);
rows = result.rows;
}
res.json({ changes: rows });
} catch (err) {
console.error('[Ivanti Findings] GET /bu-changes error:', err.message);