mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 18:33:01 +00:00
use ServerQueryInput properly
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user