feat: change global role on administration page (#61)
* feat: change global role on administration page * feat: change global role on administration page test code todo * feat: change global role on administration page test code * feat: change global role on administration page * feat: change global role on administration page * feat: change global role on administration page * feat: change global role on administration page * feat: change global role on administration page
This commit is contained in:
@@ -47,4 +47,32 @@ async function searchUsers(jwt: string, projectId: number, searchText: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export { findUser, searchUsers };
|
||||
async function updateUserRole(jwt: string, userId: number, newRole: number) {
|
||||
const updateUserData = {
|
||||
newRole,
|
||||
};
|
||||
|
||||
const fetchOptions = {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
body: JSON.stringify(updateUserData),
|
||||
};
|
||||
|
||||
const url = `${apiServer}/users/${userId}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, fetchOptions);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error: any) {
|
||||
console.error('Error fetching data:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
export { findUser, searchUsers, updateUserRole };
|
||||
|
||||
Reference in New Issue
Block a user