Files
tower/apps/web/app/api/org/rules/[id]/route.ts
T

33 lines
1.3 KiB
TypeScript

import { getApiBaseUrl, jsonResponse } from '../../../../_lib/api';
export const dynamic = 'force-dynamic';
async function getOrgToken(): Promise<string | undefined> {
const { cookies } = await import('next/headers');
return (await cookies()).get('tower_org_token')?.value;
}
export async function PATCH(req: Request, { params }: { params: Promise<{ id: string }> }): Promise<Response> {
const { id } = await params;
const token = await getOrgToken();
const body = await req.json().catch(() => ({}));
const res = await fetch(`${getApiBaseUrl()}/org/rules/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json', Accept: 'application/json', ...(token ? { Authorization: `Bearer ${token}` } : {}) },
body: JSON.stringify(body),
cache: 'no-store',
});
return jsonResponse(await res.json(), res.status);
}
export async function DELETE(_req: Request, { params }: { params: Promise<{ id: string }> }): Promise<Response> {
const { id } = await params;
const token = await getOrgToken();
const res = await fetch(`${getApiBaseUrl()}/org/rules/${id}`, {
method: 'DELETE',
headers: { Accept: 'application/json', ...(token ? { Authorization: `Bearer ${token}` } : {}) },
cache: 'no-store',
});
return res.ok ? jsonResponse({ ok: true }, 200) : jsonResponse(await res.json(), res.status);
}