SpaceNinjaServer/src/helpers/loginHelpers.ts

24 lines
715 B
TypeScript
Raw Normal View History

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 => {
if (!loginRequest || typeof loginRequest !== "object") {
throw new Error("incorrect or missing login request data");
}
2023-05-19 15:22:48 -03: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
) {
return {
email: parseEmail(loginRequest.email),
2024-09-03 17:23:42 +03:00
password: parseString(loginRequest.password)
};
}
2023-05-19 15:22:48 -03:00
throw new Error("incorrect login request");
2023-05-19 15:22:48 -03:00
};
export { toLoginRequest };