DeleteProject Handler + API function, ber till gud att denna funkar first try
This commit is contained in:
		
							parent
							
								
									a5e3d4259d
								
							
						
					
					
						commit
						67723bfccc
					
				
					 7 changed files with 172 additions and 0 deletions
				
			
		|  | @ -248,6 +248,16 @@ interface API { | |||
|    * @param {string} token Your token | ||||
|    */ | ||||
|   getUsername(id: number, token: string): Promise<APIResponse<string>>; | ||||
| 
 | ||||
|   /** | ||||
|    * Deletes a WeeklyReport from the database | ||||
|    * @param {number} reportId The id of the report to delete | ||||
|    * @param {string} token The authentication token | ||||
|    */ | ||||
|   deleteWeeklyReport( | ||||
|     reportId: number, | ||||
|     token: string, | ||||
|   ): Promise<APIResponse<string>>; | ||||
| } | ||||
| 
 | ||||
| /** An instance of the API */ | ||||
|  | @ -929,4 +939,27 @@ export const api: API = { | |||
|       return { success: false, message: "Failed to get username" }; | ||||
|     } | ||||
|   }, | ||||
| 
 | ||||
|   async deleteWeeklyReport( | ||||
|     reportId: number, | ||||
|     token: string, | ||||
|   ): Promise<APIResponse<string>> { | ||||
|     try { | ||||
|       const response = await fetch(`/api/deleteReport/${reportId}`, { | ||||
|         method: "DELETE", | ||||
|         headers: { | ||||
|           "Content-Type": "application/json", | ||||
|           Authorization: "Bearer " + token, | ||||
|         }, | ||||
|       }); | ||||
| 
 | ||||
|       if (!response.ok) { | ||||
|         return { success: false, message: "Failed to delete report" }; | ||||
|       } else { | ||||
|         return { success: true, message: "Report deleted" }; | ||||
|       } | ||||
|     } catch (e) { | ||||
|       return { success: false, message: "Failed to delete report" }; | ||||
|     } | ||||
|   }, | ||||
| }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 al8763be
						al8763be