Files
co-lite/solvway-admin-portal/app/api/roles/[id]/route.ts
T
ngqileandClaude Opus 5.5 49966586ca fix(admin-portal): match the screens to the Co-Lite backend after the browser check
- Login copy describes the event CRM instead of orders and payouts.
- Role dialog has no parent field; the role routes require a trimmed name and forward only {name}.
- New-user banner says a temporary password was emailed; TEMP_PASSWORD_NOT_SENT shows a message and a link back to users.
- Username is read-only when editing.
- Password hint and an 8-character minimum match the backend admin password rules.

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

36 lines
1.4 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 { AdminRoleEntity } from "@/app/lib/types";
type Ctx = { params: Promise<{ id: string }> };
export async function GET(_req: NextRequest, { params }: Ctx) {
const token = await getToken();
if (!token) return unauthorized();
const { id } = await params;
const result = await callMobileApi<AdminRoleEntity>(`/api/admin/roles/${encodeURIComponent(id)}`, { token });
if (!result.ok) return errorResponse(result);
return NextResponse.json(result.data);
}
export async function PUT(req: NextRequest, { params }: Ctx) {
const token = await getToken();
if (!token) return unauthorized();
const { id } = await params;
const body = await req.json().catch(() => ({}));
// The backend takes only {name}; new roles are always filed under the super admin.
const name = (body as Partial<AdminRoleEntity>).name?.trim();
if (!name) {
return badRequest("Role name is required.");
}
const result = await callMobileApi<AdminRoleEntity>(`/api/admin/roles/${encodeURIComponent(id)}`, {
method: "PUT",
body: { name },
token,
});
if (!result.ok) return errorResponse(result);
return NextResponse.json(result.data);
}