import { Request, Router } from "express";
import ClientRoute from "./client";
import UserRoute from "./user";
import RegCodeRoute from "./regcode";
import PermissionRoute from "./permission";
import { GetUserMiddleware } from "../middlewares/user";
import RequestError, { HttpStatusCode } from "../../helper/request_error";

const AdminRoute: Router = Router();

AdminRoute.use(GetUserMiddleware(true, true), (req: Request, res, next) => {
   if (!req.isAdmin)
      throw new RequestError(
         "You have no permission to access this API",
         HttpStatusCode.FORBIDDEN
      );
   else next();
});

AdminRoute.use("/client", ClientRoute);
AdminRoute.use("/regcode", RegCodeRoute);
AdminRoute.use("/user", UserRoute);
AdminRoute.use("/permission", PermissionRoute);
export default AdminRoute;
