frontend server utility improvement

This commit is contained in:
Oliver Bryan
2025-12-31 17:57:55 +00:00
parent c7d261048b
commit 70ef02f790
19 changed files with 381 additions and 182 deletions

View File

@@ -0,0 +1,30 @@
import { getAuthHeaders, getServerURL } from "@/lib/utils";
import type { ServerQueryInput } from "..";
export async function byUser({
userId,
onSuccess,
onError,
}: {
userId: number;
} & ServerQueryInput) {
const url = new URL(`${getServerURL()}/organisations/by-user`);
url.searchParams.set("userId", `${userId}`);
const res = await fetch(url.toString(), {
headers: getAuthHeaders(),
});
if (!res.ok) {
const error = await res.text();
onError?.(error || `failed to create organisation (${res.status})`);
} else {
const data = await res.json();
if (!data.id) {
onError?.(`failed to create organisation (${res.status})`);
return;
}
onSuccess?.(data, res);
}
}