From 828e7cc45db7c89d0c51b898ec27822b0c10d560 Mon Sep 17 00:00:00 2001 From: Jordan Ramos Date: Wed, 13 May 2026 14:36:05 -0600 Subject: [PATCH] Sync FP submission lifecycle_status from Ivanti currentState on fetch When GET /submissions enriches submissions with Ivanti API data, it now checks if batch.currentState (APPROVED, REJECTED, REWORK) differs from the local lifecycle_status and updates the DB accordingly. This ensures approved submissions get filtered out of the queue panel as intended. Also changed safeText() to return null for non-string Ivanti note values (arrays/objects) instead of JSON-stringifying them. The notes array filters nulls via .filter(Boolean) so non-string data is simply hidden. --- backend/routes/ivantiFpWorkflow.js | 16 ++++++++++++++++ frontend/src/components/pages/ReportingPage.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/routes/ivantiFpWorkflow.js b/backend/routes/ivantiFpWorkflow.js index 933f634..2b1a392 100644 --- a/backend/routes/ivantiFpWorkflow.js +++ b/backend/routes/ivantiFpWorkflow.js @@ -302,6 +302,22 @@ function createIvantiFpWorkflowRouter() { } } } catch (e) { console.error('Error enriching submissions with Ivanti notes:', e.message); } + + // Sync lifecycle_status from Ivanti currentState when it differs + const STATE_MAP = { 'APPROVED': 'approved', 'REJECTED': 'rejected', 'REWORK': 'rework' }; + for (const sub of submissions) { + if (!sub.ivanti_current_state) continue; + const mappedStatus = STATE_MAP[sub.ivanti_current_state.toUpperCase()]; + if (mappedStatus && mappedStatus !== sub.lifecycle_status) { + try { + await pool.query( + `UPDATE ivanti_fp_submissions SET lifecycle_status = $1, updated_at = NOW() WHERE id = $2`, + [mappedStatus, sub.id] + ); + sub.lifecycle_status = mappedStatus; + } catch (syncErr) { console.error(`Failed to sync lifecycle_status for submission ${sub.id}:`, syncErr.message); } + } + } } } res.json(submissions); diff --git a/frontend/src/components/pages/ReportingPage.js b/frontend/src/components/pages/ReportingPage.js index c0d7755..c6a5135 100644 --- a/frontend/src/components/pages/ReportingPage.js +++ b/frontend/src/components/pages/ReportingPage.js @@ -4090,7 +4090,7 @@ function FpEditModal({ open, onClose, submission, queueItems, onSuccess }) { const safeText = (val) => { if (!val) return null; if (typeof val === 'string') return val; - try { return JSON.stringify(val); } catch { return String(val); } + return null; }; const notes = [ safeText(submission.ivanti_rework_note) && { label: 'Rework Note', text: safeText(submission.ivanti_rework_note) },