Created the account.ts routes
This commit is contained in:
26
src/routes/v1/account.ts
Normal file
26
src/routes/v1/account.ts
Normal 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;
|
Reference in New Issue
Block a user