From 1d1b4d2a71b251e4b5e9e06523768302944c8b80 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 3 Feb 2026 07:02:47 -0500 Subject: [PATCH] fix: exclude RMM alert tickets (source=8) from kiosk stats - show only human-generated tickets --- app/api/kiosk/activity/route.ts | 3 ++- app/api/kiosk/stats/route.ts | 35 ++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/api/kiosk/activity/route.ts b/app/api/kiosk/activity/route.ts index 673a232..bf6db7e 100644 --- a/app/api/kiosk/activity/route.ts +++ b/app/api/kiosk/activity/route.ts @@ -3,7 +3,7 @@ import { postgresClient } from '@/lib/services/postgres-client'; export async function GET(request: NextRequest) { try { - // Get recent ticket activity for ticker feed + // Get recent ticket activity for ticker feed - exclude RMM alerts (source = 8) const activityResult = await postgresClient.query( `SELECT t.ticket_number, @@ -18,6 +18,7 @@ export async function GET(request: NextRequest) { LEFT JOIN companies c ON t.company_id = c.id LEFT JOIN statuses s ON t.status = s.value WHERE t.completed_date IS NULL + AND (t.source IS NULL OR t.source != 8) ORDER BY t.last_activity_date DESC NULLS LAST LIMIT 50` ); diff --git a/app/api/kiosk/stats/route.ts b/app/api/kiosk/stats/route.ts index 7bad715..7d00eb9 100644 --- a/app/api/kiosk/stats/route.ts +++ b/app/api/kiosk/stats/route.ts @@ -3,58 +3,65 @@ import { postgresClient } from '@/lib/services/postgres-client'; export async function GET(request: NextRequest) { try { - // Critical tickets (Priority 1-3) + // Critical tickets (Priority 1-3) - exclude RMM alerts (source = 8) const criticalTicketsResult = await postgresClient.query( `SELECT COUNT(*) as count FROM tickets WHERE completed_date IS NULL - AND priority <= 3` + AND priority <= 3 + AND (source IS NULL OR source != 8)` ); - // Tickets waiting engagement (specific statuses) + // Tickets waiting engagement (specific statuses) - exclude RMM alerts const waitingTicketsResult = await postgresClient.query( `SELECT COUNT(*) as count FROM tickets WHERE completed_date IS NULL - AND status IN (21, 9, 19)` + AND status IN (21, 9, 19) + AND (source IS NULL OR source != 8)` ); - // Stale tickets (no activity in 7+ days) + // Stale tickets (no activity in 7+ days) - exclude RMM alerts const staleTicketsResult = await postgresClient.query( `SELECT COUNT(*) as count FROM tickets WHERE completed_date IS NULL - AND last_activity_date < NOW() - INTERVAL '7 days'` + AND last_activity_date < NOW() - INTERVAL '7 days' + AND (source IS NULL OR source != 8)` ); - // Overdue tickets + // Overdue tickets - exclude RMM alerts const overdueTicketsResult = await postgresClient.query( `SELECT COUNT(*) as count FROM tickets WHERE completed_date IS NULL - AND due_date_time < NOW()` + AND due_date_time < NOW() + AND (source IS NULL OR source != 8)` ); - // Total open tickets + // Total open tickets - exclude RMM alerts const openTicketsResult = await postgresClient.query( `SELECT COUNT(*) as count FROM tickets - WHERE completed_date IS NULL` + WHERE completed_date IS NULL + AND (source IS NULL OR source != 8)` ); - // Tickets closed today + // Tickets closed today - exclude RMM alerts const closedTodayResult = await postgresClient.query( `SELECT COUNT(*) as count FROM tickets - WHERE DATE(completed_date) = CURRENT_DATE` + WHERE DATE(completed_date) = CURRENT_DATE + AND (source IS NULL OR source != 8)` ); - // Average resolution time (last 30 days) + // Average resolution time (last 30 days) - exclude RMM alerts const avgResolutionResult = await postgresClient.query( `SELECT AVG(EXTRACT(EPOCH FROM (completed_date - create_date))/3600) as avg_hours FROM tickets WHERE completed_date >= NOW() - INTERVAL '30 days' - AND completed_date IS NOT NULL` + AND completed_date IS NOT NULL + AND (source IS NULL OR source != 8)` ); // Time entries this week