import { NextRequest, NextResponse } from 'next/server'; import { withAuth, withPermission } from '@/lib/api/helpers'; import { getRevenueForecast } from '@/lib/services/dashboard.service'; import { parseRangeSlug, rangeToBounds } from '@/lib/analytics/range'; /** * GET /api/v1/dashboard/forecast * GET /api/v1/dashboard/forecast?range=7d|30d|90d|today|custom-- * * Same range semantics as /kpis — the weighted forecast scopes to * interests whose createdAt falls inside the window when range is set, * or all-time when not. */ export const GET = withAuth( withPermission('reports', 'view_dashboard', async (req: NextRequest, ctx) => { const url = new URL(req.url); const rangeSlug = url.searchParams.get('range'); const range = rangeSlug ? parseRangeSlug(rangeSlug) : null; const bounds = range ? rangeToBounds(range) : null; const result = await getRevenueForecast(ctx.portId, bounds); return NextResponse.json(result); }), );