62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { API_BASE_URL } from "@config/config_frontend";
|
|
|
|
async function api<T>(path: string, init?: RequestInit): Promise<T> {
|
|
const response = await fetch(`${API_BASE_URL}${path}`, {
|
|
credentials: "include",
|
|
...init,
|
|
headers: { "Content-Type": "application/json", ...init?.headers },
|
|
});
|
|
const result = (await response.json()) as T & { detail?: string };
|
|
if (!response.ok) throw new Error(result.detail ?? "Request failed");
|
|
return result;
|
|
}
|
|
|
|
export function getMasterDashboard(): Promise<Record<string, unknown>> {
|
|
return api("/security/master/dashboard");
|
|
}
|
|
|
|
export function getMembers(): Promise<Record<string, unknown>> {
|
|
return api("/security/master/members");
|
|
}
|
|
|
|
export function getJoinRequests(): Promise<Record<string, unknown>> {
|
|
return api("/security/master/join-requests");
|
|
}
|
|
|
|
export function decideJoinRequest(
|
|
requestId: number,
|
|
approved: boolean,
|
|
comment?: string,
|
|
): Promise<Record<string, unknown>> {
|
|
return api(`/security/master/join-requests/${requestId}/decision`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ approved, comment }),
|
|
});
|
|
}
|
|
|
|
export function removeMember(userId: number): Promise<Record<string, unknown>> {
|
|
return api(`/security/master/members/${userId}/remove`, { method: "POST" });
|
|
}
|
|
|
|
export function getAdminDashboard(): Promise<Record<string, unknown>> {
|
|
return api("/security/admin/dashboard");
|
|
}
|
|
|
|
export function getAdminCollection(
|
|
collection: "companies" | "users" | "support",
|
|
): Promise<Record<string, unknown>> {
|
|
return api(`/security/admin/${collection}`);
|
|
}
|
|
|
|
export function updateAdminStatus(
|
|
entity: "company" | "user" | "support",
|
|
targetId: number,
|
|
status: string,
|
|
reason: string,
|
|
): Promise<Record<string, unknown>> {
|
|
return api(`/security/admin/${entity}/${targetId}/status`, {
|
|
method: "PATCH",
|
|
body: JSON.stringify({ status, reason }),
|
|
});
|
|
}
|