Fix remediation plan and resolution date missing from compliance table

Add ci.resolution_date and ci.remediation_plan to the GET /items endpoint
SELECT clause and update groupByHostname() to aggregate them as first-non-null
across each hostname's metric rows. The frontend already rendered these columns
but the list endpoint never fetched the data from the database.

Includes exploration and preservation property tests for groupByHostname().
This commit is contained in:
Jordan Ramos
2026-05-27 12:54:31 -06:00
parent ea875e9193
commit d65411b0d7
3 changed files with 554 additions and 1 deletions

View File

@@ -227,6 +227,7 @@ function groupByHostname(rows, noteHostnames) {
seen_count: row.seen_count || 1, first_seen: row.first_seen || null,
last_seen: row.last_seen || null, resolved_on: row.resolved_on || null,
has_notes: noteHostnames.has(row.hostname),
resolution_date: null, remediation_plan: null,
};
}
const dev = deviceMap[row.hostname];
@@ -237,6 +238,8 @@ function groupByHostname(rows, noteHostnames) {
if ((row.seen_count || 1) > dev.seen_count) dev.seen_count = row.seen_count;
if (row.first_seen && (!dev.first_seen || row.first_seen < dev.first_seen)) dev.first_seen = row.first_seen;
if (row.last_seen && (!dev.last_seen || row.last_seen > dev.last_seen)) dev.last_seen = row.last_seen;
if (row.resolution_date && !dev.resolution_date) dev.resolution_date = row.resolution_date;
if (row.remediation_plan && !dev.remediation_plan) dev.remediation_plan = row.remediation_plan;
}
return Object.values(deviceMap).map(({ _seenMetricIds, ...dev }) => dev);
}
@@ -598,6 +601,7 @@ function createComplianceRouter(upload) {
const { rows } = await pool.query(
`SELECT DISTINCT ON (ci.hostname, ci.metric_id)
ci.hostname, ci.ip_address, ci.device_type, ci.team, ci.metric_id, ci.metric_desc, ci.category, ci.status, ci.seen_count,
ci.resolution_date, ci.remediation_plan,
fu.report_date AS first_seen, lu.report_date AS last_seen, ru.report_date AS resolved_on
FROM compliance_items ci
LEFT JOIN compliance_uploads fu ON ci.first_seen_upload_id = fu.id
@@ -1736,4 +1740,4 @@ function createComplianceRouter(upload) {
return router;
}
module.exports = { createComplianceRouter, bucketAgingItems, computeWaterfall, persistUpload };
module.exports = { createComplianceRouter, bucketAgingItems, computeWaterfall, persistUpload, groupByHostname };