diff --git a/src/routes/v1/account.ts b/src/routes/v1/account.ts new file mode 100644 index 0000000..24b3654 --- /dev/null +++ b/src/routes/v1/account.ts @@ -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; \ No newline at end of file