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 | export const dynamic = "force-dynamic"; /** * Cohort Analysis API Route * * GET - Get customer cohort analysis data */ import { NextRequest, NextResponse } from "next/server"; import { withAdmin, withErrorHandling, successResponse, ApiSuccessResponse, ApiErrorResponse, } from "@/lib/api"; import { getCohortAnalysis, type CohortAnalysisResult } from "@/lib/analytics/services"; /** * GET /api/admin/analytics/cohorts * Get customer cohort analysis * * Query params: * - months: Number of months to analyze (default: 6) */ async function handleGet( request: NextRequest ): Promise<NextResponse<ApiSuccessResponse<CohortAnalysisResult> | ApiErrorResponse>> { const { searchParams } = new URL(request.url); const months = parseInt(searchParams.get("months") || "6", 10); // Validate inputs const validMonths = Math.min(Math.max(months, 1), 12); const analysis = await getCohortAnalysis(validMonths); return successResponse(analysis); } export const GET = withErrorHandling(withAdmin(handleGet)); |