mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
add + remove users from organisation
This commit is contained in:
32
packages/frontend/src/lib/server/organisation/addMember.ts
Normal file
32
packages/frontend/src/lib/server/organisation/addMember.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user