36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { getApiBaseUrl, jsonResponse } from '../../../../_lib/api';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
export async function GET(_req: Request, { params }: { params: Promise<{ id: string }> }): Promise<Response> {
|
|
const { id } = await params;
|
|
const token = await (await import('next/headers')).cookies().then(c => c.get('tower_super_token')?.value);
|
|
const res = await fetch(`${getApiBaseUrl()}/admin/tenants/${id}`, {
|
|
headers: {
|
|
Accept: 'application/json',
|
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
},
|
|
cache: 'no-store',
|
|
});
|
|
const body = await res.json();
|
|
return jsonResponse(body, res.status);
|
|
}
|
|
|
|
export async function PATCH(req: Request, { params }: { params: Promise<{ id: string }> }): Promise<Response> {
|
|
const { id } = await params;
|
|
const body = await req.json().catch(() => ({}));
|
|
const token = await (await import('next/headers')).cookies().then(c => c.get('tower_super_token')?.value);
|
|
const res = await fetch(`${getApiBaseUrl()}/admin/tenants/${id}`, {
|
|
method: 'PATCH',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Accept: 'application/json',
|
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
},
|
|
body: JSON.stringify(body),
|
|
cache: 'no-store',
|
|
});
|
|
const payload = await res.json();
|
|
return jsonResponse(payload, res.status);
|
|
}
|