Added getAllUsers to API
This commit is contained in:
parent
a72aea1382
commit
8300fb3a6f
1 changed files with 31 additions and 1 deletions
|
@ -45,6 +45,8 @@ interface API {
|
|||
getUserProjects(token: string): Promise<APIResponse<Project[]>>;
|
||||
/** Gets a project from id*/
|
||||
getProject(id: number): Promise<APIResponse<Project>>;
|
||||
/** Gets a project from id*/
|
||||
getAllUsers(token: string): Promise<APIResponse<string[]>>;
|
||||
}
|
||||
|
||||
// Export an instance of the API
|
||||
|
@ -81,7 +83,7 @@ export const api: API = {
|
|||
token: string,
|
||||
): Promise<APIResponse<User>> {
|
||||
try {
|
||||
const response = await fetch("/api/userdelete", {
|
||||
const response = await fetch(`/api/userdelete/${username}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
@ -278,4 +280,32 @@ export const api: API = {
|
|||
};
|
||||
}
|
||||
},
|
||||
|
||||
// Gets all users
|
||||
async getAllUsers(token: string): Promise<APIResponse<string[]>> {
|
||||
try {
|
||||
const response = await fetch("/api/users/all", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
message: "Failed to get users",
|
||||
});
|
||||
} else {
|
||||
const data = (await response.json()) as string[];
|
||||
return Promise.resolve({ success: true, data });
|
||||
}
|
||||
} catch (e) {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
message: "API is not ok",
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue