Merge branch 'frontend' into gruppDM
This commit is contained in:
		
						commit
						7ed9398bcb
					
				
					 13 changed files with 149 additions and 38 deletions
				
			
		|  | @ -58,6 +58,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
 | ||||
|  | @ -94,7 +96,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", | ||||
|  | @ -352,4 +354,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…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Davenludd
						Davenludd