Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
28 lines
1.1 KiB
TypeScript
28 lines
1.1 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 } from "@/app/lib/server/apiRoute";
|
|
import type { AdminCompany } from "@/app/lib/types";
|
|
|
|
// Super admin only; the mobile-api answers 403 for anyone else, and validation (400) and duplicate codes (409) too.
|
|
export async function GET() {
|
|
const token = await getToken();
|
|
if (!token) return unauthorized();
|
|
const result = await callMobileApi<AdminCompany[]>("/api/admin/companies", { 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 { id, name, code, status } = (await req.json().catch(() => ({}))) as Partial<AdminCompany>;
|
|
const result = await callMobileApi<AdminCompany>("/api/admin/companies", {
|
|
method: "POST",
|
|
body: { id, name, code, status },
|
|
token,
|
|
});
|
|
if (!result.ok) return errorResponse(result);
|
|
return NextResponse.json(result.data);
|
|
}
|