Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | export const dynamic = 'force-dynamic'; /** * Admin Support Analytics API * GET /api/admin/support/analytics - Get support analytics summary */ import { NextRequest, NextResponse } from 'next/server'; import { Session } from 'next-auth'; import { withAdmin, withErrorHandling, ApiError, ApiSuccessResponse, ApiErrorResponse, } from '@/lib/api'; import { SupportAnalyticsService } from '@/services'; // ============================================================================ // HANDLERS // ============================================================================ /** * GET /api/admin/support/analytics * Get support analytics summary */ async function handleGet( request: NextRequest, _context: unknown, session: Session ): Promise<NextResponse<ApiSuccessResponse<unknown> | ApiErrorResponse>> { const { searchParams } = request.nextUrl; const period = searchParams.get('period') || '7d'; // 7d, 30d, 90d, custom const startParam = searchParams.get('start'); const endParam = searchParams.get('end'); // Calculate date range let startDate: Date; let endDate = new Date(); if (period === 'custom' && startParam && endParam) { startDate = new Date(startParam); endDate = new Date(endParam); if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) { throw ApiError.badRequest('Invalid date format'); } } else { const days = period === '30d' ? 30 : period === '90d' ? 90 : 7; startDate = new Date(); startDate.setDate(startDate.getDate() - days); } // Log analytics access SupportAnalyticsService.logAccess(session.user.id, 'summary'); // Get analytics summary const summary = await SupportAnalyticsService.getSummary({ startDate, endDate, }); return NextResponse.json({ success: true, data: summary, }); } // ============================================================================ // EXPORTS // ============================================================================ export const GET = withErrorHandling(withAdmin(handleGet)); |