Files
Checkmate/server/src/api/routes/authRoute.ts
T

48 lines
2.1 KiB
TypeScript
Raw Normal View History

2026-01-21 10:36:03 -08:00
import { Router, RequestHandler } from "express";
2026-06-11 10:42:05 -07:00
import { isAllowed } from "@/api/middleware/isAllowed.js";
import { imageUpload } from "@/api/middleware/upload.js";
2026-06-09 12:34:15 -07:00
import { IAuthController } from "@/api/controllers/authController.js";
2025-04-20 11:29:53 -07:00
class AuthRoutes {
2026-01-21 10:36:03 -08:00
private router: Router;
2026-03-20 11:52:53 -07:00
private authController: IAuthController;
2026-01-21 10:36:03 -08:00
2026-03-20 11:52:53 -07:00
constructor(authController: IAuthController, verifyJWT: RequestHandler) {
2025-04-20 11:29:53 -07:00
this.router = Router();
this.authController = authController;
this.initRoutes(verifyJWT);
2025-04-20 11:29:53 -07:00
}
2026-01-21 10:36:03 -08:00
initRoutes(verifyJWT: RequestHandler) {
2026-06-11 10:42:05 -07:00
this.router.post("/register", imageUpload.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);
2026-06-11 10:42:05 -07:00
this.router.post("/users", verifyJWT, isAllowed(["superadmin"]), imageUpload.single("profileImage"), this.authController.createUser);
2026-03-06 14:18:27 -05:00
this.router.get("/users/:userId", verifyJWT, isAllowed(["admin", "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);
2026-03-06 14:18:27 -05:00
this.router.delete("/users/:userId", verifyJWT, isAllowed(["admin", "superadmin"]), this.authController.deleteUserById);
2025-07-21 10:34:04 -07:00
this.router.patch(
"/user",
verifyJWT,
imageUpload.single("profileImage"),
isAllowed(["admin", "superadmin", "user"]),
this.authController.editUser
);
this.router.delete("/user", verifyJWT, isAllowed(["admin", "superadmin", "user"]), this.authController.deleteUser);
2025-04-20 11:29:53 -07:00
}
getRouter() {
return this.router;
}
}
export default AuthRoutes;