mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
33 lines
874 B
TypeScript
33 lines
874 B
TypeScript
import { getAuthHeaders, getServerURL } from "@/lib/utils";
|
|
import type { ServerQueryInput } from "..";
|
|
|
|
export async function addMember({
|
|
organisationId,
|
|
userId,
|
|
role = "member",
|
|
onSuccess,
|
|
onError,
|
|
}: {
|
|
organisationId: number;
|
|
userId: number;
|
|
role?: string;
|
|
} & ServerQueryInput) {
|
|
const url = new URL(`${getServerURL()}/organisation/add-member`);
|
|
url.searchParams.set("organisationId", `${organisationId}`);
|
|
url.searchParams.set("userId", `${userId}`);
|
|
url.searchParams.set("role", role);
|
|
|
|
const res = await fetch(url.toString(), {
|
|
method: "POST",
|
|
headers: getAuthHeaders(),
|
|
});
|
|
|
|
if (!res.ok) {
|
|
const error = await res.text();
|
|
onError?.(error || `failed to add member (${res.status})`);
|
|
} else {
|
|
const data = await res.json();
|
|
onSuccess?.(data, res);
|
|
}
|
|
}
|