- Add QBO OAuth2 client with token refresh (lib/services/qbo-client.ts) - Add QBO sync service for invoices, payments, deposits, purchases, journal entries, reports (lib/services/qbo-sync-service.ts) - Add QBO types (lib/types/qbo.ts) - Add API routes: /api/qbo/auth, /api/qbo/sync, /api/qbo/disconnect - Add /admin/qbo status and sync management page - Add legal pages: /legal/eula, /legal/privacy (Intuit app assessment) - Add QBO nav link under Admin - Fix reports: remove invalid summarize_column_by, add accounting_method from Preferences API, add showrows=all&showcols=all - Add CashFlow report type alongside P&L and BalanceSheet - Add NoReportData check to skip empty report months - Add intuit_tid capture in error messages - Add redirect: follow for cluster routing - Migration 051: qbo_tokens, qbo_invoices, qbo_payments, qbo_deposits, qbo_transactions, qbo_reports tables Also includes earlier work: - Ping flap suppression pipeline step - Ticket digest reports with LLM analysis - Zabbix WAN monitor and gap analysis - Kiosk is_deleted filter fixes - Datto RMM ping target enrichment - Entity sync soft-delete detection
70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
/**
|
|
* Ticket Digest Report API
|
|
* POST /api/reports/ticket-digest — Generate and deliver a digest report
|
|
* Body: { period: 'daily' | 'weekly' | 'monthly', webhookIds?: number[] }
|
|
* GET /api/reports/ticket-digest — Get report history
|
|
* GET /api/reports/ticket-digest?preview=daily — Aggregate data only (no LLM, no delivery)
|
|
*/
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getTicketDigestService, DigestPeriod } from '@/lib/services/ticket-digest-service';
|
|
|
|
const VALID_PERIODS: DigestPeriod[] = ['daily', 'weekly', 'monthly'];
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json();
|
|
const period = body.period as DigestPeriod;
|
|
|
|
if (!period || !VALID_PERIODS.includes(period)) {
|
|
return NextResponse.json(
|
|
{ error: `Invalid period. Must be one of: ${VALID_PERIODS.join(', ')}` },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const service = getTicketDigestService();
|
|
const result = await service.run(period, body.channelIds);
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
period,
|
|
stats: result.stats.overview,
|
|
noiseCount: result.stats.noise_candidates.length,
|
|
analysisLength: result.analysis.length,
|
|
deliveryResults: result.deliveryResults,
|
|
processingTimeMs: result.processingTimeMs,
|
|
});
|
|
} catch (error) {
|
|
const msg = error instanceof Error ? error.message : String(error);
|
|
console.error('[TICKET-DIGEST API] Error:', msg);
|
|
return NextResponse.json({ error: msg }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const { searchParams } = new URL(request.url);
|
|
const preview = searchParams.get('preview') as DigestPeriod | null;
|
|
|
|
const service = getTicketDigestService();
|
|
|
|
if (preview && VALID_PERIODS.includes(preview)) {
|
|
const stats = await service.aggregate(preview);
|
|
return NextResponse.json({ stats });
|
|
}
|
|
|
|
// Return history + config + available notification channels
|
|
const [history, config, channels] = await Promise.all([
|
|
service.getHistory(20),
|
|
service.getConfig(),
|
|
service.getAvailableChannels(),
|
|
]);
|
|
|
|
return NextResponse.json({ history, config, channels });
|
|
} catch (error) {
|
|
const msg = error instanceof Error ? error.message : String(error);
|
|
console.error('[TICKET-DIGEST API] Error:', msg);
|
|
return NextResponse.json({ error: msg }, { status: 500 });
|
|
}
|
|
}
|