import { NextRequest, NextResponse } from "next/server"; import { getDashboardRows } from "@/lib/calc"; // GET /api/dashboard?region&costItem&year -> aggregated table rows. export async function GET(req: NextRequest) { const { searchParams } = new URL(req.url); const region = searchParams.get("region") ?? "All"; const costItem = searchParams.get("costItem") ?? "All"; const yearParam = searchParams.get("year"); const year = yearParam ? parseInt(yearParam, 10) : NaN; if (Number.isNaN(year)) { return NextResponse.json({ error: "year is required" }, { status: 400 }); } const rows = await getDashboardRows({ region, costItem, year }); return NextResponse.json({ rows }); }