Merge remote-tracking branch 'origin/frontend' into BumBranch
This commit is contained in:
		
						commit
						09f2a2202f
					
				
					 13 changed files with 287 additions and 48 deletions
				
			
		|  | @ -6,6 +6,8 @@ import { | |||
|   NewProject, | ||||
|   UserProjectMember, | ||||
|   WeeklyReport, | ||||
|   StrNameChange, | ||||
|   NewProjMember, | ||||
| } from "../Types/goTypes"; | ||||
| 
 | ||||
| /** | ||||
|  | @ -132,6 +134,20 @@ interface API { | |||
|     projectName: string, | ||||
|     token: string, | ||||
|   ): Promise<APIResponse<UserProjectMember[]>>; | ||||
|   /** | ||||
|    * Changes the username of a user in the database. | ||||
|    * @param {StrNameChange} data The object containing the previous and new username. | ||||
|    * @param {string} token The authentication token. | ||||
|    * @returns {Promise<APIResponse<void>>} A promise resolving to an API response. | ||||
|    */ | ||||
|   changeUserName( | ||||
|     data: StrNameChange, | ||||
|     token: string, | ||||
|   ): Promise<APIResponse<void>>; | ||||
|   addUserToProject( | ||||
|     user: NewProjMember, | ||||
|     token: string, | ||||
|   ): Promise<APIResponse<NewProjMember>>; | ||||
| 
 | ||||
|   removeProject( | ||||
|     projectName: string, | ||||
|  | @ -174,19 +190,17 @@ export const api: API = { | |||
|   ): Promise<APIResponse<User>> { | ||||
|     try { | ||||
|       const response = await fetch(`/api/userdelete/${username}`, { | ||||
|         method: "POST", | ||||
|         method: "DELETE", | ||||
|         headers: { | ||||
|           "Content-Type": "application/json", | ||||
|           Authorization: "Bearer " + token, | ||||
|         }, | ||||
|         body: JSON.stringify(username), | ||||
|       }); | ||||
| 
 | ||||
|       if (!response.ok) { | ||||
|         return { success: false, message: "Failed to remove user" }; | ||||
|         return { success: false, message: "Could not remove user" }; | ||||
|       } else { | ||||
|         const data = (await response.json()) as User; | ||||
|         return { success: true, data }; | ||||
|         return { success: true }; | ||||
|       } | ||||
|     } catch (e) { | ||||
|       return { success: false, message: "Failed to remove user" }; | ||||
|  | @ -248,6 +262,30 @@ export const api: API = { | |||
|     } | ||||
|   }, | ||||
| 
 | ||||
|   async addUserToProject( | ||||
|     user: NewProjMember, | ||||
|     token: string, | ||||
|   ): Promise<APIResponse<NewProjMember>> { | ||||
|     try { | ||||
|       const response = await fetch("/api/addUserToProject", { | ||||
|         method: "PUT", | ||||
|         headers: { | ||||
|           "Content-Type": "application/json", | ||||
|           Authorization: "Bearer " + token, | ||||
|         }, | ||||
|         body: JSON.stringify(user), | ||||
|       }); | ||||
| 
 | ||||
|       if (!response.ok) { | ||||
|         return { success: false, message: "Failed to add member" }; | ||||
|       } else { | ||||
|         return { success: true, message: "Added member" }; | ||||
|       } | ||||
|     } catch (e) { | ||||
|       return { success: false, message: "Failed to add member" }; | ||||
|     } | ||||
|   }, | ||||
| 
 | ||||
|   async renewToken(token: string): Promise<APIResponse<string>> { | ||||
|     try { | ||||
|       const response = await fetch("/api/loginrenew", { | ||||
|  | @ -490,6 +528,30 @@ export const api: API = { | |||
|     } | ||||
|   }, | ||||
| 
 | ||||
|   async changeUserName( | ||||
|     data: StrNameChange, | ||||
|     token: string, | ||||
|   ): Promise<APIResponse<void>> { | ||||
|     try { | ||||
|       const response = await fetch("/api/changeUserName", { | ||||
|         method: "PUT", | ||||
|         headers: { | ||||
|           "Content-Type": "application/json", | ||||
|           Authorization: "Bearer " + token, | ||||
|         }, | ||||
|         body: JSON.stringify(data), | ||||
|       }); | ||||
| 
 | ||||
|       if (!response.ok) { | ||||
|         return { success: false, message: "Failed to change username" }; | ||||
|       } else { | ||||
|         return { success: true }; | ||||
|       } | ||||
|     } catch (e) { | ||||
|       return { success: false, message: "Failed to change username" }; | ||||
|     } | ||||
|   }, | ||||
| 
 | ||||
|   async removeProject( | ||||
|     projectName: string, | ||||
|     token: string, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 al8763be
						al8763be