fixed some database backend stuff
This commit is contained in:
		
							parent
							
								
									26b69a1cb6
								
							
						
					
					
						commit
						223f953648
					
				
					 8 changed files with 58 additions and 41 deletions
				
			
		|  | @ -18,27 +18,28 @@ if all went well, you will get the status 200 in response.data.status | |||
| to check if the request was accepted or declined, check response.data.response, it will be either true or false depending on if it worked, or not. | ||||
| */ | ||||
| 
 | ||||
| export const sendToDatabase = (data: any): Promise<boolean> => { | ||||
|   return axios.post("http://localhost:5000/interstellar_ai/db", data) | ||||
|     .then(response => { | ||||
|       const status = response.data.status; | ||||
|       const success = response.data.response; | ||||
|       postMessage({ status, success }); | ||||
|       return success;  // Ensure success is returned to the caller
 | ||||
|     }) | ||||
|     .catch(error => { | ||||
|       postMessage({ status: 500, success: false }); | ||||
|       return false;  // Return false in case of an error
 | ||||
|     }); | ||||
| export const sendToDatabase = async (data: any): Promise<boolean> => { | ||||
|   try { | ||||
|     const response = await axios.post("http://localhost:5000/interstellar_ai/db", data); | ||||
|     const status = response.data.status; | ||||
|     const success = response.data.response; | ||||
|     postMessage({ status, success }); | ||||
|     console.log(status); | ||||
|     return success; | ||||
|   } catch (error) { | ||||
|     postMessage({ status: 500, success: false }); | ||||
|     console.log("NO"); | ||||
|     return false; | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| // Functions for each action
 | ||||
| export const createAccount = async (username: string, email: string, password: string) => { | ||||
|   const data = { | ||||
|     action: "create_account", | ||||
|     username, | ||||
|     email, | ||||
|     password, | ||||
|     username: username, | ||||
|     email: email, | ||||
|     password: password, | ||||
|   }; | ||||
|   return await sendToDatabase(data); | ||||
| }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Patrick_Pluto
						Patrick_Pluto