Lists, adds, renames, orders and activates/deactivates interests, gated by BO_INTERESTS. API errors map to field messages under Name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { NextResponse, type NextRequest } from "next/server";
|
|
import { callMobileApi } from "@/app/lib/server/mobileApi";
|
|
import { getToken } from "@/app/lib/server/session";
|
|
import { errorResponse, unauthorized, badRequest } from "@/app/lib/server/apiRoute";
|
|
import type { AdminInterestEntity } from "@/app/lib/types";
|
|
|
|
export async function GET(_req: NextRequest) {
|
|
const token = await getToken();
|
|
if (!token) return unauthorized();
|
|
const result = await callMobileApi<AdminInterestEntity[]>("/api/admin/interests", { token });
|
|
if (!result.ok) return errorResponse(result);
|
|
return NextResponse.json(result.data);
|
|
}
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const token = await getToken();
|
|
if (!token) return unauthorized();
|
|
const body = await req.json().catch(() => ({}));
|
|
const name = (body as Partial<AdminInterestEntity>).name?.trim();
|
|
if (!name) {
|
|
return badRequest("Name is required.", { code: "REQUIRED_FIELD", details: { field: "name" } });
|
|
}
|
|
const result = await callMobileApi<AdminInterestEntity>(
|
|
"/api/admin/interests",
|
|
{
|
|
method: "POST",
|
|
body: { name, active: (body as Partial<AdminInterestEntity>).active, sortOrder: (body as Partial<AdminInterestEntity>).sortOrder },
|
|
token,
|
|
},
|
|
);
|
|
if (!result.ok) return errorResponse(result);
|
|
return NextResponse.json(result.data);
|
|
}
|