wulf-pulse/app/api/kiosk/activity/route.ts
root 26bfd503f1 feat: add kiosk settings UI and co-managed client filtering
- Created kiosk_settings table for configuration storage
- Added API endpoints for kiosk settings (GET/POST)
- Filter out co-managed clients (configurable company exclusions)
- Built comprehensive settings UI at /kiosk/settings
- Allow excluding specific companies from kiosk display
- Configurable cycle interval, refresh interval, and RMM alert toggle
- Updated dashboard link to point to settings page
- Applied company exclusion filter to all ticket queries and activity feed
- Default excludes Thrasher Group (ID: 29861361)
2026-02-03 08:32:42 -05:00

65 lines
2.2 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { postgresClient } from '@/lib/services/postgres-client';
async function getExcludedCompanyIds(): Promise<number[]> {
try {
const result = await postgresClient.query(
`SELECT setting_value FROM kiosk_settings WHERE setting_key = 'excluded_company_ids'`
);
const value = result.rows[0]?.setting_value || '';
return value ? value.split(',').map((id: string) => parseInt(id.trim())).filter((id: number) => !isNaN(id)) : [];
} catch (error) {
console.error('Error fetching excluded company IDs:', error);
return [];
}
}
export async function GET(request: NextRequest) {
try {
// Get excluded company IDs (co-managed clients)
const excludedCompanyIds = await getExcludedCompanyIds();
const excludeCompanyFilter = excludedCompanyIds.length > 0
? `AND t.company_id NOT IN (${excludedCompanyIds.join(',')})`
: '';
// Get recent ticket activity for ticker feed - exclude RMM alerts (source = 8) and co-managed clients
const activityResult = await postgresClient.query(
`SELECT
t.ticket_number,
t.title,
t.priority,
t.status,
t.create_date,
t.last_activity_date,
c.company_name,
s.label as status_label
FROM tickets t
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)
${excludeCompanyFilter}
ORDER BY t.last_activity_date DESC NULLS LAST
LIMIT 50`
);
const activities = activityResult.rows.map((row: any) => ({
ticketNumber: row.ticket_number,
title: row.title,
priority: row.priority,
status: row.status,
statusLabel: row.status_label,
companyName: row.company_name,
createDate: row.create_date,
lastActivityDate: row.last_activity_date,
}));
return NextResponse.json({ activities });
} catch (error) {
console.error('Error fetching kiosk activity:', error);
return NextResponse.json(
{ error: 'Failed to fetch kiosk activity' },
{ status: 500 }
);
}
}