Files
co-lite/solvway-admin-portal/app/api/leads/[[...path]]/route.ts
T
ngqileandClaude Opus 5.5 82b6943474 feat(admin-portal): leads listing and lead detail
Lead Listing with search and server paging, lead detail with event
history, shared-contact warning and an edit form under BO_LEADS_EDIT,
and a View lead link from the event lead edit page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-27 16:53:44 +08:00

24 lines
1.2 KiB
TypeScript

import { NextResponse, type NextRequest } from "next/server";
import { callMobileApi } from "@/app/lib/server/mobileApi";
import { getToken } from "@/app/lib/server/session";
import { badRequest, errorResponse, unauthorized } from "@/app/lib/server/apiRoute";
// One proxy for every /api/admin/leads endpoint; mobile-api owns validation and the BO_LEADS guards.
type Ctx = { params: Promise<{ path?: string[] }> };
async function forward(req: NextRequest, { params }: Ctx, method?: "PUT") {
const token = await getToken();
if (!token) return unauthorized();
const { path = [] } = await params; // [[...path]]: the list call has no segment
if (path.some((s) => s === "." || s === "..")) return badRequest("Invalid path.");
const target = `/api/admin/leads${path.map(encodeURIComponent).map((s) => `/${s}`).join("")}${new URL(req.url).search}`;
const result = method
? await callMobileApi<unknown>(target, { method, body: await req.json().catch(() => ({})), token })
: await callMobileApi<unknown>(target, { token });
if (!result.ok) return errorResponse(result);
return NextResponse.json(result.data);
}
export const GET = (req: NextRequest, ctx: Ctx) => forward(req, ctx);
export const PUT = (req: NextRequest, ctx: Ctx) => forward(req, ctx, "PUT");