2026-01-21 10:36:03 -08:00
|
|
|
import { Router, RequestHandler } from "express";
|
|
|
|
|
import { isAllowed } from "../middleware/isAllowed.js";
|
2025-04-20 11:29:53 -07:00
|
|
|
import multer from "multer";
|
|
|
|
|
|
|
|
|
|
const upload = multer();
|
|
|
|
|
|
|
|
|
|
class AuthRoutes {
|
2026-01-21 10:36:03 -08:00
|
|
|
private router: Router;
|
|
|
|
|
private authController: any;
|
|
|
|
|
|
|
|
|
|
constructor(authController: any, verifyJWT: RequestHandler) {
|
2025-04-20 11:29:53 -07:00
|
|
|
this.router = Router();
|
|
|
|
|
this.authController = authController;
|
2026-01-20 22:40:06 +00:00
|
|
|
this.initRoutes(verifyJWT);
|
2025-04-20 11:29:53 -07:00
|
|
|
}
|
|
|
|
|
|
2026-01-21 10:36:03 -08:00
|
|
|
initRoutes(verifyJWT: RequestHandler) {
|
2025-07-21 10:34:04 -07:00
|
|
|
this.router.post("/register", upload.single("profileImage"), this.authController.registerUser);
|
2025-04-20 11:29:53 -07:00
|
|
|
this.router.post("/login", this.authController.loginUser);
|
|
|
|
|
|
|
|
|
|
this.router.post("/recovery/request", this.authController.requestRecovery);
|
|
|
|
|
this.router.post("/recovery/validate", this.authController.validateRecovery);
|
|
|
|
|
this.router.post("/recovery/reset/", this.authController.resetPassword);
|
2025-07-21 10:34:04 -07:00
|
|
|
|
|
|
|
|
this.router.get("/users/superadmin", this.authController.checkSuperadminExists);
|
2025-07-21 11:05:48 -07:00
|
|
|
|
2025-07-21 10:34:04 -07:00
|
|
|
this.router.get("/users", verifyJWT, isAllowed(["admin", "superadmin"]), this.authController.getAllUsers);
|
2025-07-22 12:27:17 -07:00
|
|
|
this.router.get("/users/:userId", verifyJWT, isAllowed(["superadmin"]), this.authController.getUserById);
|
2026-02-07 20:17:59 +00:00
|
|
|
this.router.patch("/users/:userId", verifyJWT, isAllowed(["superadmin"]), this.authController.editUserById);
|
|
|
|
|
this.router.patch("/users/:userId/password", verifyJWT, isAllowed(["superadmin"]), this.authController.editUserPasswordById);
|
2025-07-21 10:34:04 -07:00
|
|
|
|
2026-02-07 20:17:59 +00:00
|
|
|
this.router.patch("/user", verifyJWT, upload.single("profileImage"), this.authController.editUser);
|
2025-07-21 11:05:48 -07:00
|
|
|
this.router.delete("/user", verifyJWT, this.authController.deleteUser);
|
2025-04-20 11:29:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getRouter() {
|
|
|
|
|
return this.router;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default AuthRoutes;
|