diff --git a/src/app/api/v1/rep-dashboard/route.ts b/src/app/api/v1/rep-dashboard/route.ts new file mode 100644 index 0000000..4dabd7b --- /dev/null +++ b/src/app/api/v1/rep-dashboard/route.ts @@ -0,0 +1,26 @@ +import { NextRequest, NextResponse } from "next/server"; +import { getBrowserSessionUser } from "@/lib/server/browser-session"; +import { getRepDashboardData } from "@/lib/server/rep-dashboard-service"; + +/** + * GET /api/v1/rep-dashboard + * + * Read model for `/dashboard2`. Scopes every query to the logged-in + * user's own id (via `customer.rep`) — unlike `/api/v1/dashboard`, + * there is no role gate: a non-rep just gets zeros everywhere. + */ +export const runtime = "nodejs"; +export const dynamic = "force-dynamic"; + +export async function GET(req: NextRequest) { + try { + const sessionUser = await getBrowserSessionUser(req); + const data = await getRepDashboardData(sessionUser.id); + return NextResponse.json(data); + } catch (error) { + const message = + error instanceof Error ? error.message : "Failed to load rep dashboard"; + const status = (error as Error & { status?: number }).status || 500; + return NextResponse.json({ error: message }, { status }); + } +} \ No newline at end of file