2023-06-02 00:20:49 -03:00
|
|
|
import { ILoginRequest } from "@/src/types/loginTypes";
|
2023-05-19 15:22:48 -03:00
|
|
|
import { parseEmail, parseNumber, parseString } from "./general";
|
|
|
|
|
|
|
|
const toLoginRequest = (loginRequest: unknown): ILoginRequest => {
|
2023-05-23 20:42:06 -04:00
|
|
|
if (!loginRequest || typeof loginRequest !== "object") {
|
|
|
|
throw new Error("incorrect or missing login request data");
|
|
|
|
}
|
2023-05-19 15:22:48 -03:00
|
|
|
|
2023-05-23 20:42:06 -04:00
|
|
|
// TODO: function that checks whether every field of interface is in object
|
|
|
|
if (
|
|
|
|
"email" in loginRequest &&
|
2024-09-03 17:23:42 +03:00
|
|
|
"password" in loginRequest
|
2023-05-23 20:42:06 -04:00
|
|
|
) {
|
|
|
|
return {
|
|
|
|
email: parseEmail(loginRequest.email),
|
2024-09-03 17:23:42 +03:00
|
|
|
password: parseString(loginRequest.password)
|
2023-05-23 20:42:06 -04:00
|
|
|
};
|
|
|
|
}
|
2023-05-19 15:22:48 -03:00
|
|
|
|
2023-05-23 20:42:06 -04:00
|
|
|
throw new Error("incorrect login request");
|
2023-05-19 15:22:48 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
export { toLoginRequest };
|