refac: group members frontend integration

This commit is contained in:
Timothy Jaeryang Baek
2025-11-18 03:44:26 -05:00
parent 0a72d047ef
commit 73734b186b
5 changed files with 152 additions and 32 deletions
+70
View File
@@ -160,3 +160,73 @@ export const deleteGroupById = async (token: string, id: string) => {
return res;
};
export const addUserToGroup = async (token: string, id: string, userIds: string[]) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/groups/id/${id}/users/add`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
authorization: `Bearer ${token}`
},
body: JSON.stringify({
user_ids: userIds
})
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.then((json) => {
return json;
})
.catch((err) => {
error = err.detail;
console.error(err);
return null;
});
if (error) {
throw error;
}
return res;
};
export const removeUserFromGroup = async (token: string, id: string, userIds: string[]) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/groups/id/${id}/users/remove`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
authorization: `Bearer ${token}`
},
body: JSON.stringify({
user_ids: userIds
})
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.then((json) => {
return json;
})
.catch((err) => {
error = err.detail;
console.error(err);
return null;
});
if (error) {
throw error;
}
return res;
};