Fix calendar SLA dates not highlighting after Postgres migration
PostgreSQL DATE columns return JS Date objects which serialize to ISO timestamps (e.g. 2025-05-22T00:00:00.000Z). The CalendarWidget expects plain YYYY-MM-DD strings for its date key lookup. Added formatDate() helper to normalize due_date and last_found_on before sending the API response.
This commit is contained in:
@@ -10,6 +10,19 @@ const pool = require('../db');
|
||||
|
||||
const SYNC_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
// PostgreSQL DATE columns return JS Date objects — normalize to 'YYYY-MM-DD' strings
|
||||
function formatDate(val) {
|
||||
if (!val) return null;
|
||||
if (val instanceof Date) {
|
||||
const y = val.getFullYear();
|
||||
const m = String(val.getMonth() + 1).padStart(2, '0');
|
||||
const d = String(val.getDate()).padStart(2, '0');
|
||||
return `${y}-${m}-${d}`;
|
||||
}
|
||||
// Already a string — strip any time portion (e.g. "2025-05-22T00:00:00.000Z")
|
||||
return String(val).slice(0, 10);
|
||||
}
|
||||
|
||||
// Configurable BU filter — broadened via env var to support multi-tenancy.
|
||||
// Users see only their assigned teams' findings (filtered at query time).
|
||||
const BU_FILTER_VALUE = process.env.IVANTI_BU_FILTER || 'NTS-AEO-ACCESS-ENG,NTS-AEO-STEAM';
|
||||
@@ -1033,8 +1046,8 @@ function createIvantiFindingsRouter(db, requireAuth) {
|
||||
dns: row.dns,
|
||||
status: row.status,
|
||||
slaStatus: row.sla_status,
|
||||
dueDate: row.due_date,
|
||||
lastFoundOn: row.last_found_on,
|
||||
dueDate: formatDate(row.due_date),
|
||||
lastFoundOn: formatDate(row.last_found_on),
|
||||
buOwnership: row.bu_ownership,
|
||||
cves: row.cves || [],
|
||||
workflow: row.workflow_id ? { id: row.workflow_id, state: row.workflow_state, type: row.workflow_type } : null,
|
||||
@@ -1089,8 +1102,8 @@ function createIvantiFindingsRouter(db, requireAuth) {
|
||||
dns: row.dns,
|
||||
status: row.status,
|
||||
slaStatus: row.sla_status,
|
||||
dueDate: row.due_date,
|
||||
lastFoundOn: row.last_found_on,
|
||||
dueDate: formatDate(row.due_date),
|
||||
lastFoundOn: formatDate(row.last_found_on),
|
||||
buOwnership: row.bu_ownership,
|
||||
cves: row.cves || [],
|
||||
workflow: row.workflow_id ? { id: row.workflow_id, state: row.workflow_state, type: row.workflow_type } : null,
|
||||
|
||||
Reference in New Issue
Block a user