first part of refactoring
This commit is contained in:
parent
f09ffc6b86
commit
6a6954023c
9 changed files with 140 additions and 172 deletions
|
@ -21,7 +21,7 @@ to check if the request was accepted or declined, check response.data.response,
|
|||
const apiURL = new URL("http://localhost:5000/interstellar_ai/db")
|
||||
apiURL.hostname = window.location.hostname;
|
||||
|
||||
export const sendToDatabase = async (data: any): Promise<boolean> => {
|
||||
export const sendToDatabase = async (data: object): Promise<boolean> => {
|
||||
try {
|
||||
const response = await axios.post(apiURL.href, data);
|
||||
const status = response.data.status;
|
||||
|
@ -30,11 +30,12 @@ export const sendToDatabase = async (data: any): Promise<boolean> => {
|
|||
return success;
|
||||
} catch (error) {
|
||||
postMessage({ status: 500, success: false });
|
||||
console.log(error)
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const sendToDatabaseAndGetString = async (data: any): Promise<string> => {
|
||||
export const sendToDatabaseAndGetString = async (data: object): Promise<string> => {
|
||||
try {
|
||||
const response = await axios.post(apiURL.href, data);
|
||||
const status = response.data.status;
|
||||
|
@ -43,6 +44,7 @@ export const sendToDatabaseAndGetString = async (data: any): Promise<string> =>
|
|||
return success;
|
||||
} catch (error) {
|
||||
postMessage({ status: 500, success: false });
|
||||
console.log(error)
|
||||
return "false";
|
||||
}
|
||||
};
|
||||
|
@ -99,7 +101,7 @@ export const getName = async (usernameOrEmail: string, password: string): Promis
|
|||
return await sendToDatabaseAndGetString(data);
|
||||
};
|
||||
|
||||
export const changeData = async (usernameOrEmail: string, password: string, newData: any) => {
|
||||
export const changeData = async (usernameOrEmail: string, password: string, newData: object) => {
|
||||
const data = {
|
||||
action: "change_settings",
|
||||
username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail,
|
||||
|
@ -117,7 +119,7 @@ export const checkCredentials = async (usernameOrEmail: string, password: string
|
|||
email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined,
|
||||
password,
|
||||
};
|
||||
var sendBack = await sendToDatabase(data);
|
||||
const sendBack = await sendToDatabase(data);
|
||||
if (sendBack) {
|
||||
localStorage.setItem("accountEmail", await getEmail(usernameOrEmail, password))
|
||||
localStorage.setItem("accountName", await getName(usernameOrEmail, password))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue