From 4df83d36dd1a0f614cae7d97af36a76cd154d4f4 Mon Sep 17 00:00:00 2001 From: jramos Date: Thu, 9 Apr 2026 16:11:52 -0600 Subject: [PATCH] fix: include hostname overrides in all queue endpoint responses --- backend/routes/ivantiTodoQueue.js | 60 ++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/backend/routes/ivantiTodoQueue.js b/backend/routes/ivantiTodoQueue.js index 928e8f2..288ab6c 100644 --- a/backend/routes/ivantiTodoQueue.js +++ b/backend/routes/ivantiTodoQueue.js @@ -161,7 +161,11 @@ function createIvantiTodoQueueRouter(db, requireAuth) { // Fetch all inserted rows const placeholders = insertedIds.map(() => '?').join(','); db.all( - `SELECT * FROM ivanti_todo_queue WHERE id IN (${placeholders})`, + `SELECT q.*, o.value AS override_hostname + FROM ivanti_todo_queue q + LEFT JOIN ivanti_finding_overrides o + ON o.finding_id = q.finding_id AND o.field = 'hostName' + WHERE q.id IN (${placeholders})`, insertedIds, (fetchErr, fetchedRows) => { if (fetchErr) { @@ -169,10 +173,15 @@ function createIvantiTodoQueueRouter(db, requireAuth) { return res.status(500).json({ error: 'Internal server error.' }); } - const items = (fetchedRows || []).map((r) => ({ - ...r, - cves: r.cves_json ? JSON.parse(r.cves_json) : [], - })); + const items = (fetchedRows || []).map((r) => { + const item = { + ...r, + hostname: r.override_hostname || r.hostname, + cves: r.cves_json ? JSON.parse(r.cves_json) : [], + }; + delete item.override_hostname; + return item; + }); // Audit log (fire-and-forget) logAudit(db, { @@ -255,13 +264,23 @@ function createIvantiTodoQueueRouter(db, requireAuth) { return res.status(500).json({ error: 'Internal server error.' }); } db.get( - 'SELECT * FROM ivanti_todo_queue WHERE id = ?', + `SELECT q.*, o.value AS override_hostname + FROM ivanti_todo_queue q + LEFT JOIN ivanti_finding_overrides o + ON o.finding_id = q.finding_id AND o.field = 'hostName' + WHERE q.id = ?`, [this.lastID], (err2, row) => { if (err2 || !row) { return res.status(201).json({ id: this.lastID, message: 'Added to queue.' }); } - res.status(201).json({ ...row, cves: row.cves_json ? JSON.parse(row.cves_json) : [] }); + const result = { + ...row, + hostname: row.override_hostname || row.hostname, + cves: row.cves_json ? JSON.parse(row.cves_json) : [], + }; + delete result.override_hostname; + res.status(201).json(result); } ); } @@ -343,13 +362,23 @@ function createIvantiTodoQueueRouter(db, requireAuth) { return res.status(500).json({ error: 'Internal server error.' }); } db.get( - 'SELECT * FROM ivanti_todo_queue WHERE id = ?', + `SELECT q.*, o.value AS override_hostname + FROM ivanti_todo_queue q + LEFT JOIN ivanti_finding_overrides o + ON o.finding_id = q.finding_id AND o.field = 'hostName' + WHERE q.id = ?`, [id], (err3, row) => { if (err3 || !row) { return res.json({ message: 'Queue item updated.' }); } - res.json({ ...row, cves: row.cves_json ? JSON.parse(row.cves_json) : [] }); + const result = { + ...row, + hostname: row.override_hostname || row.hostname, + cves: row.cves_json ? JSON.parse(row.cves_json) : [], + }; + delete result.override_hostname; + res.json(result); } ); } @@ -426,7 +455,11 @@ function createIvantiTodoQueueRouter(db, requireAuth) { // --- Fetch the inserted row --- db.get( - 'SELECT * FROM ivanti_todo_queue WHERE id = ?', + `SELECT q.*, o.value AS override_hostname + FROM ivanti_todo_queue q + LEFT JOIN ivanti_finding_overrides o + ON o.finding_id = q.finding_id AND o.field = 'hostName' + WHERE q.id = ?`, [newId], (fetchErr, row) => { if (fetchErr || !row) { @@ -450,10 +483,13 @@ function createIvantiTodoQueueRouter(db, requireAuth) { ipAddress: req.ip, }); - return res.status(201).json({ + const result = { ...row, + hostname: row.override_hostname || row.hostname, cves: row.cves_json ? JSON.parse(row.cves_json) : [], - }); + }; + delete result.override_hostname; + return res.status(201).json(result); } ); }