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 | export const dynamic = "force-dynamic"; /** * Revenue Forecast API Route * * GET - Get revenue forecast predictions */ import { NextRequest, NextResponse } from "next/server"; import { withAdmin, withErrorHandling, successResponse, ApiSuccessResponse, ApiErrorResponse, } from "@/lib/api"; import { getRevenueForecast, type RevenueForecast } from "@/lib/analytics/services"; /** * GET /api/admin/analytics/revenue/forecast * Get revenue forecast * * Query params: * - days: Days ahead to forecast (default: 7) * - historical: Days of historical data to use (default: 30) */ async function handleGet( request: NextRequest ): Promise<NextResponse<ApiSuccessResponse<RevenueForecast> | ApiErrorResponse>> { const { searchParams } = new URL(request.url); const daysAhead = parseInt(searchParams.get("days") || "7", 10); const historicalDays = parseInt(searchParams.get("historical") || "30", 10); // Validate inputs const validDaysAhead = Math.min(Math.max(daysAhead, 1), 30); const validHistorical = Math.min(Math.max(historicalDays, 7), 90); const forecast = await getRevenueForecast(validDaysAhead, validHistorical); return successResponse(forecast); } export const GET = withErrorHandling(withAdmin(handleGet)); |