use ServerQueryInput properly

This commit is contained in:
Oliver Bryan
2026-01-13 15:33:55 +00:00
parent 4e93eb5878
commit ca371b1751
21 changed files with 284 additions and 329 deletions

View File

@@ -1,23 +1,17 @@
import type { OrganisationResponse } from "@issue/shared";
import { 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(), {
export async function byUser({ onSuccess, onError }: ServerQueryInput<OrganisationResponse[]>) {
const res = await fetch(`${getServerURL()}/organisations/by-user`, {
credentials: "include",
});
if (!res.ok) {
const error = await res.text();
onError?.(error || `failed to get organisations (${res.status})`);
const error = await res.json().catch(() => res.text());
const message =
typeof error === "string" ? error : error.error || `failed to get organisations (${res.status})`;
onError?.(message);
} else {
const data = await res.json();
onSuccess?.(data, res);