Add possibility for admin to suspend/delete
This commit is contained in:
42
src/app/api/admin/tenants/[name]/suspend/route.ts
Normal file
42
src/app/api/admin/tenants/[name]/suspend/route.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { requirePlatformRole } from "@/lib/session";
|
||||
import { getTenant, patchTenantSpec } from "@/lib/k8s";
|
||||
|
||||
/**
|
||||
* POST /api/admin/tenants/[name]/suspend
|
||||
* Toggle suspend on a PiecedTenant CR.
|
||||
* Body: { suspend: true } or { suspend: false }
|
||||
*/
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ name: string }> }
|
||||
) {
|
||||
try {
|
||||
await requirePlatformRole();
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
const { name } = await params;
|
||||
const body = await request.json().catch(() => ({}));
|
||||
const suspend = body.suspend === true;
|
||||
|
||||
const tenant = await getTenant(name);
|
||||
if (!tenant) {
|
||||
return NextResponse.json({ error: "Tenant not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
try {
|
||||
const updated = await patchTenantSpec(name, { suspend });
|
||||
return NextResponse.json({
|
||||
message: suspend ? "Tenant suspended." : "Tenant resumed.",
|
||||
tenant: updated,
|
||||
});
|
||||
} catch (e: any) {
|
||||
console.error("Failed to update tenant suspend state:", e);
|
||||
return NextResponse.json(
|
||||
{ error: `Failed to update tenant: ${e.message}` },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user