Created the account.ts routes

This commit is contained in:
2023-01-15 19:41:52 +01:00
parent 4bf0576032
commit a083935704

26
src/routes/v1/account.ts Normal file
View File

@ -0,0 +1,26 @@
import { Request, Response, Router } from "express";
import { validateSchema } from "@utils/error";
import { registerValidation, verificationValidation } from "./validations/account";
import { createAccount, verifyAccount } from "../../controller/account";
const app: Router = Router();
app.post("/register", async (req: Request, res: Response) => {
if (validateSchema(res, registerValidation, req.body)) return;
const account = await createAccount(req.body);
if (account) return res.json(account);
res.json({ message: "Your account has been successfully created. Check your mails to verify." });
});
app.post("/verify", async (req: Request, res: Response) => {
if (validateSchema(res, verificationValidation, req.body)) return;
const verified = await verifyAccount({ id: req.body.id, code: parseInt(req.body.code) });
if (verified) return res.json(verified);
res.json({ message: "Your account has been successfully verified." });
});
export default app;