Files
it_cost_dashboard/src/app/api/dashboard/route.ts
T
2026-09-08 17:46:28 +08:00

19 lines
700 B
TypeScript

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 });
}