29 lines
909 B
TypeScript
29 lines
909 B
TypeScript
import { apiFetch, jsonResponse } from '../../../_lib/api';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
export async function PUT(
|
|
req: Request,
|
|
{ params }: { params: Promise<{ id: string }> },
|
|
): Promise<Response> {
|
|
const { id } = await params;
|
|
const body = await req.json();
|
|
const res = await apiFetch(`/admin/rules/${id}`, {
|
|
method: 'PUT',
|
|
body: JSON.stringify(body),
|
|
});
|
|
const payload = await res.json();
|
|
return jsonResponse(payload, res.status);
|
|
}
|
|
|
|
export async function DELETE(
|
|
_req: Request,
|
|
{ params }: { params: Promise<{ id: string }> },
|
|
): Promise<Response> {
|
|
const { id } = await params;
|
|
const res = await apiFetch(`/admin/rules/${id}`, { method: 'DELETE' });
|
|
if (res.status === 204) return new Response(null, { status: 204 });
|
|
const body = await res.text();
|
|
return new Response(body, { status: res.status, headers: { 'Content-Type': 'application/json' } });
|
|
}
|