2023-06-02 00:20:49 -03:00
|
|
|
import { Account } from "@/src/models/loginModel";
|
|
|
|
import { IDatabaseAccount } from "@/src/types/loginTypes";
|
2023-05-19 15:22:48 -03:00
|
|
|
|
|
|
|
const isCorrectPassword = (requestPassword: string, databasePassword: string): boolean => {
|
2023-05-23 20:42:06 -04:00
|
|
|
return requestPassword === databasePassword;
|
2023-05-19 15:22:48 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
const createAccount = async (accountData: IDatabaseAccount) => {
|
2023-05-23 20:42:06 -04:00
|
|
|
console.log("test", accountData);
|
|
|
|
const account = new Account(accountData);
|
|
|
|
try {
|
|
|
|
await account.save();
|
|
|
|
return account.toJSON();
|
|
|
|
} catch (error) {
|
|
|
|
if (error instanceof Error) {
|
|
|
|
throw new Error(error.message);
|
|
|
|
}
|
|
|
|
throw new Error("error creating account that is not of instance Error");
|
2023-05-19 15:22:48 -03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export { isCorrectPassword, createAccount };
|