feat: add /api/v1/rep-dashboard route
This commit is contained in:
parent
3637eef83a
commit
afb396b03b
1 changed files with 26 additions and 0 deletions
26
src/app/api/v1/rep-dashboard/route.ts
Normal file
26
src/app/api/v1/rep-dashboard/route.ts
Normal file
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue