diff --git a/server/src/api/routes/authRoute.ts b/server/src/api/routes/authRoute.ts deleted file mode 100644 index 3b202a502..000000000 --- a/server/src/api/routes/authRoute.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { Router, RequestHandler } from "express"; -import { isAllowed } from "@/api/middleware/isAllowed.js"; -import { imageUpload } from "@/api/middleware/upload.js"; -import { IAuthController } from "@/api/controllers/authController.js"; - -class AuthRoutes { - private router: Router; - private authController: IAuthController; - - constructor(authController: IAuthController, verifyJWT: RequestHandler) { - this.router = Router(); - this.authController = authController; - this.initRoutes(verifyJWT); - } - - initRoutes(verifyJWT: RequestHandler) { - this.router.post("/register", imageUpload.single("profileImage"), this.authController.registerUser); - 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); - - this.router.get("/users/superadmin", this.authController.checkSuperadminExists); - - this.router.get("/users", verifyJWT, isAllowed(["admin", "superadmin"]), this.authController.getAllUsers); - this.router.post("/users", verifyJWT, isAllowed(["superadmin"]), imageUpload.single("profileImage"), this.authController.createUser); - this.router.get("/users/:userId", verifyJWT, isAllowed(["admin", "superadmin"]), this.authController.getUserById); - this.router.patch("/users/:userId", verifyJWT, isAllowed(["superadmin"]), this.authController.editUserById); - this.router.patch("/users/:userId/password", verifyJWT, isAllowed(["superadmin"]), this.authController.editUserPasswordById); - this.router.delete("/users/:userId", verifyJWT, isAllowed(["admin", "superadmin"]), this.authController.deleteUserById); - - 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); - } - - getRouter() { - return this.router; - } -} - -export default AuthRoutes; diff --git a/server/src/api/routes/authRoutes.ts b/server/src/api/routes/authRoutes.ts new file mode 100644 index 000000000..ba92091bd --- /dev/null +++ b/server/src/api/routes/authRoutes.ts @@ -0,0 +1,27 @@ +import { Router, RequestHandler } from "express"; +import { isAllowed } from "@/api/middleware/isAllowed.js"; +import { imageUpload } from "@/api/middleware/upload.js"; +import { IAuthController } from "@/api/controllers/authController.js"; + +export const createAuthRoutes = (authController: IAuthController, verifyJWT: RequestHandler): Router => { + const router = Router(); + router.post("/register", imageUpload.single("profileImage"), authController.registerUser); + router.post("/login", authController.loginUser); + + router.post("/recovery/request", authController.requestRecovery); + router.post("/recovery/validate", authController.validateRecovery); + router.post("/recovery/reset/", authController.resetPassword); + + router.get("/users/superadmin", authController.checkSuperadminExists); + + router.get("/users", verifyJWT, isAllowed(["admin", "superadmin"]), authController.getAllUsers); + router.post("/users", verifyJWT, isAllowed(["superadmin"]), imageUpload.single("profileImage"), authController.createUser); + router.get("/users/:userId", verifyJWT, isAllowed(["admin", "superadmin"]), authController.getUserById); + router.patch("/users/:userId", verifyJWT, isAllowed(["superadmin"]), authController.editUserById); + router.patch("/users/:userId/password", verifyJWT, isAllowed(["superadmin"]), authController.editUserPasswordById); + router.delete("/users/:userId", verifyJWT, isAllowed(["admin", "superadmin"]), authController.deleteUserById); + + router.patch("/user", verifyJWT, imageUpload.single("profileImage"), isAllowed(["admin", "superadmin", "user"]), authController.editUser); + router.delete("/user", verifyJWT, isAllowed(["admin", "superadmin", "user"]), authController.deleteUser); + return router; +}; diff --git a/server/src/api/routes/checkRoute.ts b/server/src/api/routes/checkRoute.ts deleted file mode 100644 index 171d79ab4..000000000 --- a/server/src/api/routes/checkRoute.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Router } from "express"; - -import { isAllowed } from "../middleware/isAllowed.js"; -import { ICheckController } from "@/api/controllers/checkController.js"; - -class CheckRoutes { - private router: Router; - private checkController: ICheckController; - - constructor(checkController: ICheckController) { - this.router = Router(); - this.checkController = checkController; - this.initRoutes(); - } - - initRoutes() { - this.router.get("/team/summary", this.checkController.getChecksSummaryByTeamId); - this.router.get("/team", this.checkController.getChecksByTeam); - this.router.delete("/team", isAllowed(["admin", "superadmin"]), this.checkController.deleteChecksByTeamId); - this.router.get("/:monitorId", this.checkController.getChecksByMonitor); - this.router.delete("/:monitorId", this.checkController.deleteChecks); - } - - getRouter() { - return this.router; - } -} - -export default CheckRoutes; diff --git a/server/src/api/routes/checkRoutes.ts b/server/src/api/routes/checkRoutes.ts new file mode 100644 index 000000000..97974f9df --- /dev/null +++ b/server/src/api/routes/checkRoutes.ts @@ -0,0 +1,14 @@ +import { Router } from "express"; + +import { isAllowed } from "../middleware/isAllowed.js"; +import { ICheckController } from "@/api/controllers/checkController.js"; + +export const createCheckRoutes = (checkController: ICheckController): Router => { + const router = Router(); + router.get("/team/summary", checkController.getChecksSummaryByTeamId); + router.get("/team", checkController.getChecksByTeam); + router.delete("/team", isAllowed(["admin", "superadmin"]), checkController.deleteChecksByTeamId); + router.get("/:monitorId", checkController.getChecksByMonitor); + router.delete("/:monitorId", checkController.deleteChecks); + return router; +}; diff --git a/server/src/api/routes/diagnosticRoute.ts b/server/src/api/routes/diagnosticRoute.ts deleted file mode 100644 index 3fe29bc1e..000000000 --- a/server/src/api/routes/diagnosticRoute.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { RequestHandler, Router } from "express"; -import { isAllowed } from "../middleware/isAllowed.js"; -import { IDiagnosticController } from "@/api/controllers/diagnosticController.js"; - -class DiagnosticRoutes { - private router: Router; - private diagnosticController: IDiagnosticController; - - constructor(diagnosticController: IDiagnosticController, verifyJWT: RequestHandler) { - this.router = Router(); - this.diagnosticController = diagnosticController; - this.initRoutes(verifyJWT); - } - - initRoutes(verifyJWT: RequestHandler) { - this.router.get("/system", verifyJWT, isAllowed(["admin", "superadmin"]), this.diagnosticController.getSystemStats); - } - - getRouter() { - return this.router; - } -} - -export default DiagnosticRoutes; diff --git a/server/src/api/routes/diagnosticRoutes.ts b/server/src/api/routes/diagnosticRoutes.ts new file mode 100644 index 000000000..680c10015 --- /dev/null +++ b/server/src/api/routes/diagnosticRoutes.ts @@ -0,0 +1,9 @@ +import { RequestHandler, Router } from "express"; +import { isAllowed } from "../middleware/isAllowed.js"; +import { IDiagnosticController } from "@/api/controllers/diagnosticController.js"; + +export const createDiagnosticRoutes = (diagnosticController: IDiagnosticController, verifyJWT: RequestHandler): Router => { + const router = Router(); + router.get("/system", verifyJWT, isAllowed(["admin", "superadmin"]), diagnosticController.getSystemStats); + return router; +}; diff --git a/server/src/api/routes/geoCheckRoutes.ts b/server/src/api/routes/geoCheckRoutes.ts index bf9178afe..08c577c0e 100644 --- a/server/src/api/routes/geoCheckRoutes.ts +++ b/server/src/api/routes/geoCheckRoutes.ts @@ -1,23 +1,9 @@ import { IGeoCheckController } from "@/api/controllers/geoCheckController.js"; import { Router } from "express"; -class GeoCheckRoutes { - private router: Router; - private geoCheckController: IGeoCheckController; +export const createGeoCheckRoutes = (geoCheckController: IGeoCheckController): Router => { + const router = Router(); + router.get("/:monitorId", geoCheckController.getGeoChecksByMonitor); - constructor(geoCheckController: IGeoCheckController) { - this.router = Router(); - this.geoCheckController = geoCheckController; - this.initRoutes(); - } - - initRoutes() { - this.router.get("/:monitorId", this.geoCheckController.getGeoChecksByMonitor); - } - - getRouter() { - return this.router; - } -} - -export default GeoCheckRoutes; + return router; +}; diff --git a/server/src/api/routes/incidentRoute.ts b/server/src/api/routes/incidentRoute.ts deleted file mode 100644 index 0f2f4485c..000000000 --- a/server/src/api/routes/incidentRoute.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Router } from "express"; -import { isAllowed } from "../middleware/isAllowed.js"; -import { IIncidentController } from "@/api/controllers/incidentController.js"; - -class IncidentRoutes { - private router: Router; - private incidentController: IIncidentController; - - constructor(incidentController: IIncidentController) { - this.router = Router(); - this.incidentController = incidentController; - this.initRoutes(); - } - - initRoutes() { - // Team routes - this.router.get("/team", this.incidentController.getIncidentsByTeam); - this.router.get("/team/summary", this.incidentController.getIncidentSummary); - - // Individual incident routes - this.router.get("/:incidentId", this.incidentController.getIncidentById); - this.router.put("/:incidentId/resolve", isAllowed(["admin", "superadmin"]), this.incidentController.resolveIncidentManually); - } - - getRouter() { - return this.router; - } -} - -export default IncidentRoutes; diff --git a/server/src/api/routes/incidentRoutes.ts b/server/src/api/routes/incidentRoutes.ts new file mode 100644 index 000000000..f9c42d0f2 --- /dev/null +++ b/server/src/api/routes/incidentRoutes.ts @@ -0,0 +1,12 @@ +import { Router } from "express"; +import { isAllowed } from "../middleware/isAllowed.js"; +import { IIncidentController } from "@/api/controllers/incidentController.js"; + +export const createIncidentRoutes = (incidentController: IIncidentController): Router => { + const router = Router(); + router.get("/team", incidentController.getIncidentsByTeam); + router.get("/team/summary", incidentController.getIncidentSummary); + router.get("/:incidentId", incidentController.getIncidentById); + router.put("/:incidentId/resolve", isAllowed(["admin", "superadmin"]), incidentController.resolveIncidentManually); + return router; +}; diff --git a/server/src/api/routes/inviteRoute.ts b/server/src/api/routes/inviteRoute.ts deleted file mode 100644 index 2e25694d2..000000000 --- a/server/src/api/routes/inviteRoute.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { RequestHandler, Router } from "express"; -import { isAllowed } from "../middleware/isAllowed.js"; -import { IInviteController } from "@/api/controllers/inviteController.js"; - -class InviteRoutes { - private router: Router; - private inviteController: IInviteController; - - constructor(inviteController: IInviteController, verifyJWT: RequestHandler) { - this.router = Router(); - this.inviteController = inviteController; - this.initRoutes(verifyJWT); - } - - initRoutes(verifyJWT: RequestHandler) { - this.router.post("/send", verifyJWT, isAllowed(["admin", "superadmin"]), this.inviteController.sendInviteEmail); - this.router.post("/verify", this.inviteController.verifyInviteToken); - this.router.post("/", verifyJWT, isAllowed(["admin", "superadmin"]), this.inviteController.getInviteToken); - } - - getRouter() { - return this.router; - } -} - -export default InviteRoutes; diff --git a/server/src/api/routes/inviteRoutes.ts b/server/src/api/routes/inviteRoutes.ts new file mode 100644 index 000000000..fe6ba9664 --- /dev/null +++ b/server/src/api/routes/inviteRoutes.ts @@ -0,0 +1,11 @@ +import { RequestHandler, Router } from "express"; +import { isAllowed } from "../middleware/isAllowed.js"; +import { IInviteController } from "@/api/controllers/inviteController.js"; + +export const createInviteRoutes = (inviteController: IInviteController, verifyJWT: RequestHandler): Router => { + const router = Router(); + router.post("/send", verifyJWT, isAllowed(["admin", "superadmin"]), inviteController.sendInviteEmail); + router.post("/verify", inviteController.verifyInviteToken); + router.post("/", verifyJWT, isAllowed(["admin", "superadmin"]), inviteController.getInviteToken); + return router; +}; diff --git a/server/src/api/routes/logRoutes.ts b/server/src/api/routes/logRoutes.ts index ef98b5189..e0de3b93b 100644 --- a/server/src/api/routes/logRoutes.ts +++ b/server/src/api/routes/logRoutes.ts @@ -1,22 +1,10 @@ import { Router } from "express"; import { isAllowed } from "@/api/middleware/isAllowed.js"; + import { ILogController } from "@/api/controllers/logController.js"; -class LogRoutes { - private router: Router; - private logController: ILogController; - constructor(logController: ILogController) { - this.router = Router(); - this.logController = logController; - this.initRoutes(); - } - initRoutes() { - this.router.get("/", isAllowed(["admin", "superadmin"]), this.logController.getLogs); - } - - getRouter() { - return this.router; - } -} - -export default LogRoutes; +export const createLogRoutes = (logController: ILogController): Router => { + const router = Router(); + router.get("/", isAllowed(["admin", "superadmin"]), logController.getLogs); + return router; +}; diff --git a/server/src/api/routes/maintenanceWindowRoute.ts b/server/src/api/routes/maintenanceWindowRoute.ts deleted file mode 100644 index 43d03ff34..000000000 --- a/server/src/api/routes/maintenanceWindowRoute.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { IMaintenanceWindowController } from "@/api/controllers/maintenanceWindowController.js"; -import { Router } from "express"; - -class MaintenanceWindowRoutes { - private router: Router; - private mwController: IMaintenanceWindowController; - - constructor(maintenanceWindowController: IMaintenanceWindowController) { - this.router = Router(); - this.mwController = maintenanceWindowController; - this.initRoutes(); - } - initRoutes() { - this.router.post("/", this.mwController.createMaintenanceWindows); - this.router.get("/team/", this.mwController.getMaintenanceWindowsByTeamId); - - this.router.get("/monitor/:monitorId", this.mwController.getMaintenanceWindowsByMonitorId); - - this.router.get("/:id", this.mwController.getMaintenanceWindowById); - this.router.patch("/:id", this.mwController.editMaintenanceWindow); - this.router.delete("/:id", this.mwController.deleteMaintenanceWindow); - } - - getRouter() { - return this.router; - } -} - -export default MaintenanceWindowRoutes; diff --git a/server/src/api/routes/maintenanceWindowRoutes.ts b/server/src/api/routes/maintenanceWindowRoutes.ts new file mode 100644 index 000000000..22c3fd94a --- /dev/null +++ b/server/src/api/routes/maintenanceWindowRoutes.ts @@ -0,0 +1,15 @@ +import { IMaintenanceWindowController } from "@/api/controllers/maintenanceWindowController.js"; +import { Router } from "express"; + +export const createMaintenanceWindowRoutes = (maintenanceWindowController: IMaintenanceWindowController): Router => { + const router = Router(); + router.post("/", maintenanceWindowController.createMaintenanceWindows); + router.get("/team/", maintenanceWindowController.getMaintenanceWindowsByTeamId); + + router.get("/monitor/:monitorId", maintenanceWindowController.getMaintenanceWindowsByMonitorId); + + router.get("/:id", maintenanceWindowController.getMaintenanceWindowById); + router.patch("/:id", maintenanceWindowController.editMaintenanceWindow); + router.delete("/:id", maintenanceWindowController.deleteMaintenanceWindow); + return router; +}; diff --git a/server/src/api/routes/monitorRoute.ts b/server/src/api/routes/monitorRoute.ts deleted file mode 100644 index 74a00637d..000000000 --- a/server/src/api/routes/monitorRoute.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { Router } from "express"; -import { isAllowed } from "@/api/middleware/isAllowed.js"; -import { IMonitorController } from "@/api/controllers/monitorController.js"; - -class MonitorRoutes { - private router: Router; - private monitorController: IMonitorController; - constructor(monitorController: IMonitorController) { - this.router = Router(); - this.monitorController = monitorController; - this.initRoutes(); - } - - initRoutes() { - // Team routes - this.router.get("/team", this.monitorController.getMonitorsByTeamId); - this.router.get("/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId); - - // Uptime routes - this.router.get("/uptime/details/:monitorId", this.monitorController.getUptimeDetailsById); - - // Hardware routes - this.router.get("/hardware/details/:monitorId", this.monitorController.getHardwareDetailsById); - - // PageSpeed routes - this.router.get("/pagespeed/details/:monitorId", this.monitorController.getPageSpeedDetailsById); - - // Geo checks routes - this.router.get("/:monitorId/geo-checks", this.monitorController.getGeoChecksByMonitorId); - - // General monitor routes - this.router.post("/pause/:monitorId", isAllowed(["admin", "superadmin"]), this.monitorController.pauseMonitor); - this.router.post("/bulk/pause", isAllowed(["admin", "superadmin"]), this.monitorController.bulkPauseMonitors); - - // Util routes - this.router.get("/certificate/:monitorId", (req, res, next) => { - this.monitorController.getMonitorCertificate(req, res, next); - }); - - // General monitor CRUD routes - this.router.patch("/notifications", isAllowed(["admin", "superadmin"]), this.monitorController.updateNotifications); - this.router.post("/", isAllowed(["admin", "superadmin"]), this.monitorController.createMonitor); - this.router.delete("/", isAllowed(["superadmin"]), this.monitorController.deleteAllMonitors); - - // Other static routes - this.router.post("/demo", isAllowed(["admin", "superadmin"]), this.monitorController.addDemoMonitors); - this.router.get("/export/json", isAllowed(["admin", "superadmin"]), this.monitorController.exportMonitorsToJSON); - this.router.post("/import/json", isAllowed(["admin", "superadmin"]), this.monitorController.importMonitorsFromJSON); - - this.router.get("/games", this.monitorController.getAllGames); - - // Individual monitor CRUD routes - this.router.get("/:monitorId", this.monitorController.getMonitorById); - this.router.patch("/:monitorId", isAllowed(["admin", "superadmin"]), this.monitorController.editMonitor); - this.router.delete("/:monitorId", isAllowed(["admin", "superadmin"]), this.monitorController.deleteMonitor); - } - - getRouter() { - return this.router; - } -} - -export default MonitorRoutes; diff --git a/server/src/api/routes/monitorRoutes.ts b/server/src/api/routes/monitorRoutes.ts new file mode 100644 index 000000000..43a94b5c4 --- /dev/null +++ b/server/src/api/routes/monitorRoutes.ts @@ -0,0 +1,50 @@ +import { Router } from "express"; +import { isAllowed } from "@/api/middleware/isAllowed.js"; +import { IMonitorController } from "@/api/controllers/monitorController.js"; + +export const createMonitorRoutes = (monitorController: IMonitorController): Router => { + const router = Router(); + + // Team routes + router.get("/team", monitorController.getMonitorsByTeamId); + router.get("/team/with-checks", monitorController.getMonitorsWithChecksByTeamId); + + // Uptime routes + router.get("/uptime/details/:monitorId", monitorController.getUptimeDetailsById); + + // Hardware routes + router.get("/hardware/details/:monitorId", monitorController.getHardwareDetailsById); + + // PageSpeed routes + router.get("/pagespeed/details/:monitorId", monitorController.getPageSpeedDetailsById); + + // Geo checks routes + router.get("/:monitorId/geo-checks", monitorController.getGeoChecksByMonitorId); + + // General monitor routes + router.post("/pause/:monitorId", isAllowed(["admin", "superadmin"]), monitorController.pauseMonitor); + router.post("/bulk/pause", isAllowed(["admin", "superadmin"]), monitorController.bulkPauseMonitors); + + // Util routes + router.get("/certificate/:monitorId", (req, res, next) => { + monitorController.getMonitorCertificate(req, res, next); + }); + + // General monitor CRUD routes + router.patch("/notifications", isAllowed(["admin", "superadmin"]), monitorController.updateNotifications); + router.post("/", isAllowed(["admin", "superadmin"]), monitorController.createMonitor); + router.delete("/", isAllowed(["superadmin"]), monitorController.deleteAllMonitors); + + // Other static routes + router.post("/demo", isAllowed(["admin", "superadmin"]), monitorController.addDemoMonitors); + router.get("/export/json", isAllowed(["admin", "superadmin"]), monitorController.exportMonitorsToJSON); + router.post("/import/json", isAllowed(["admin", "superadmin"]), monitorController.importMonitorsFromJSON); + + router.get("/games", monitorController.getAllGames); + + // Individual monitor CRUD routes + router.get("/:monitorId", monitorController.getMonitorById); + router.patch("/:monitorId", isAllowed(["admin", "superadmin"]), monitorController.editMonitor); + router.delete("/:monitorId", isAllowed(["admin", "superadmin"]), monitorController.deleteMonitor); + return router; +}; diff --git a/server/src/api/routes/notificationRoute.ts b/server/src/api/routes/notificationRoute.ts deleted file mode 100644 index 16d9a7086..000000000 --- a/server/src/api/routes/notificationRoute.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { INotificationController } from "@/api/controllers/notificationController.js"; -import { Router } from "express"; -class NotificationRoutes { - private router: Router; - private notificationController: INotificationController; - - constructor(notificationController: INotificationController) { - this.router = Router(); - this.notificationController = notificationController; - this.initializeRoutes(); - } - - initializeRoutes() { - this.router.post("/", this.notificationController.createNotification); - - this.router.post("/test/all", this.notificationController.testAllNotifications); - this.router.post("/test", this.notificationController.testNotification); - - this.router.get("/team", this.notificationController.getNotificationsByTeamId); - - this.router.get("/:id", this.notificationController.getNotificationById); - this.router.delete("/:id", this.notificationController.deleteNotification); - this.router.patch("/:id", this.notificationController.editNotification); - } - - getRouter() { - return this.router; - } -} - -export default NotificationRoutes; diff --git a/server/src/api/routes/notificationRoutes.ts b/server/src/api/routes/notificationRoutes.ts new file mode 100644 index 000000000..32ea1923c --- /dev/null +++ b/server/src/api/routes/notificationRoutes.ts @@ -0,0 +1,14 @@ +import { INotificationController } from "@/api/controllers/notificationController.js"; +import { Router } from "express"; + +export const createNotificationRoutes = (notificationController: INotificationController): Router => { + const router = Router(); + router.post("/", notificationController.createNotification); + router.post("/test/all", notificationController.testAllNotifications); + router.post("/test", notificationController.testNotification); + router.get("/team", notificationController.getNotificationsByTeamId); + router.get("/:id", notificationController.getNotificationById); + router.delete("/:id", notificationController.deleteNotification); + router.patch("/:id", notificationController.editNotification); + return router; +}; diff --git a/server/src/api/routes/queueRoute.ts b/server/src/api/routes/queueRoute.ts deleted file mode 100644 index 0a9d41bb1..000000000 --- a/server/src/api/routes/queueRoute.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Router } from "express"; -import { isAllowed } from "@/api/middleware/isAllowed.js"; -import { IJobQueueController } from "@/api/controllers/queueController.js"; -class QueueRoutes { - private router: Router; - private queueController: IJobQueueController; - - constructor(queueController: IJobQueueController) { - this.router = Router(); - this.queueController = queueController; - this.initRoutes(); - } - initRoutes() { - this.router.get("/jobs", isAllowed(["admin", "superadmin"]), this.queueController.getJobs); - - this.router.get("/metrics", isAllowed(["admin", "superadmin"]), this.queueController.getMetrics); - this.router.get("/all-metrics", isAllowed(["admin", "superadmin"]), this.queueController.getAllMetrics); - this.router.post("/flush", isAllowed(["admin", "superadmin"]), this.queueController.flushQueue); - } - - getRouter() { - return this.router; - } -} - -export default QueueRoutes; diff --git a/server/src/api/routes/queueRoutes.ts b/server/src/api/routes/queueRoutes.ts new file mode 100644 index 000000000..9a0d2f2e5 --- /dev/null +++ b/server/src/api/routes/queueRoutes.ts @@ -0,0 +1,12 @@ +import { Router } from "express"; +import { isAllowed } from "@/api/middleware/isAllowed.js"; +import { IJobQueueController } from "@/api/controllers/queueController.js"; + +export const createQueueRoutes = (queueController: IJobQueueController): Router => { + const router = Router(); + router.get("/jobs", isAllowed(["admin", "superadmin"]), queueController.getJobs); + router.get("/metrics", isAllowed(["admin", "superadmin"]), queueController.getMetrics); + router.get("/all-metrics", isAllowed(["admin", "superadmin"]), queueController.getAllMetrics); + router.post("/flush", isAllowed(["admin", "superadmin"]), queueController.flushQueue); + return router; +}; diff --git a/server/src/api/routes/settingsRoute.ts b/server/src/api/routes/settingsRoute.ts deleted file mode 100644 index 3bb0e75fd..000000000 --- a/server/src/api/routes/settingsRoute.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Router } from "express"; -import { isAllowed } from "../middleware/isAllowed.js"; -import { ISettingsController } from "@/api/controllers/settingsController.js"; - -class SettingsRoutes { - private router: Router; - private settingsController: ISettingsController; - - constructor(settingsController: ISettingsController) { - this.router = Router(); - this.settingsController = settingsController; - this.initRoutes(); - } - - initRoutes() { - this.router.get("/", this.settingsController.getAppSettings); - this.router.patch("/", isAllowed(["admin", "superadmin"]), this.settingsController.updateAppSettings); - this.router.post("/test-email", isAllowed(["admin", "superadmin"]), this.settingsController.sendTestEmail); - } - - getRouter() { - return this.router; - } -} - -export default SettingsRoutes; diff --git a/server/src/api/routes/settingsRoutes.ts b/server/src/api/routes/settingsRoutes.ts new file mode 100644 index 000000000..5b6e6c9a5 --- /dev/null +++ b/server/src/api/routes/settingsRoutes.ts @@ -0,0 +1,11 @@ +import { Router } from "express"; +import { isAllowed } from "../middleware/isAllowed.js"; +import { ISettingsController } from "@/api/controllers/settingsController.js"; + +export const createSettingsRoutes = (settingsController: ISettingsController): Router => { + const router = Router(); + router.get("/", settingsController.getAppSettings); + router.patch("/", isAllowed(["admin", "superadmin"]), settingsController.updateAppSettings); + router.post("/test-email", isAllowed(["admin", "superadmin"]), settingsController.sendTestEmail); + return router; +}; diff --git a/server/src/api/routes/statusPageRoute.ts b/server/src/api/routes/statusPageRoute.ts deleted file mode 100644 index 816c7212a..000000000 --- a/server/src/api/routes/statusPageRoute.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { IStatusPageController } from "@/api/controllers/statusPageController.js"; -import { RequestHandler, Router } from "express"; -import { isAllowed } from "@/api/middleware/isAllowed.js"; -import { imageUpload } from "@/api/middleware/upload.js"; - -class StatusPageRoutes { - private router: Router; - private statusPageController: IStatusPageController; - - constructor(statusPageController: IStatusPageController, verifyJWT: RequestHandler, verifyStatusPageAccess: RequestHandler) { - this.router = Router(); - this.statusPageController = statusPageController; - this.initRoutes(verifyJWT, verifyStatusPageAccess); - } - - initRoutes(verifyJWT: RequestHandler, verifyStatusPageAccess: RequestHandler) { - this.router.get("/team", verifyJWT, this.statusPageController.getStatusPagesByTeamId); - - this.router.post("/", imageUpload.single("logo"), verifyJWT, isAllowed(["admin", "superadmin"]), this.statusPageController.createStatusPage); - this.router.put("/:id", imageUpload.single("logo"), verifyJWT, isAllowed(["admin", "superadmin"]), this.statusPageController.updateStatusPage); - - this.router.get("/resolve", this.statusPageController.resolveStatusPageByDomain); - this.router.get("/:url", verifyStatusPageAccess, this.statusPageController.getStatusPageByUrl); - this.router.delete("/:id", verifyJWT, isAllowed(["admin", "superadmin"]), this.statusPageController.deleteStatusPage); - } - - getRouter() { - return this.router; - } -} - -export default StatusPageRoutes; diff --git a/server/src/api/routes/statusPageRoutes.ts b/server/src/api/routes/statusPageRoutes.ts new file mode 100644 index 000000000..b37ae5499 --- /dev/null +++ b/server/src/api/routes/statusPageRoutes.ts @@ -0,0 +1,19 @@ +import { IStatusPageController } from "@/api/controllers/statusPageController.js"; +import { RequestHandler, Router } from "express"; +import { isAllowed } from "@/api/middleware/isAllowed.js"; +import { imageUpload } from "@/api/middleware/upload.js"; + +export const createStatusPageRoutes = ( + statusPageController: IStatusPageController, + verifyJWT: RequestHandler, + verifyStatusPageAccess: RequestHandler +): Router => { + const router = Router(); + router.get("/team", verifyJWT, statusPageController.getStatusPagesByTeamId); + router.post("/", imageUpload.single("logo"), verifyJWT, isAllowed(["admin", "superadmin"]), statusPageController.createStatusPage); + router.put("/:id", imageUpload.single("logo"), verifyJWT, isAllowed(["admin", "superadmin"]), statusPageController.updateStatusPage); + router.get("/resolve", statusPageController.resolveStatusPageByDomain); + router.get("/:url", verifyStatusPageAccess, statusPageController.getStatusPageByUrl); + router.delete("/:id", verifyJWT, isAllowed(["admin", "superadmin"]), statusPageController.deleteStatusPage); + return router; +}; diff --git a/server/src/api/routes/tagRoutes.ts b/server/src/api/routes/tagRoutes.ts index c1a3f7972..d9632ce9c 100644 --- a/server/src/api/routes/tagRoutes.ts +++ b/server/src/api/routes/tagRoutes.ts @@ -1,28 +1,12 @@ import { ITagsController } from "@/api/controllers/tagController.js"; import { Router } from "express"; -class TagRoutes { - private router: Router; - private tagController: ITagsController; - constructor(tagController: ITagsController) { - this.router = Router(); - this.tagController = tagController; - this.initializeRoutes(); - } - - initializeRoutes() { - this.router.post("/", this.tagController.createTag); - - this.router.get("/team", this.tagController.getTagsByTeamId); - - this.router.get("/:id", this.tagController.getTagById); - this.router.delete("/:id", this.tagController.deleteTag); - this.router.patch("/:id", this.tagController.editTag); - } - - getRouter() { - return this.router; - } -} - -export default TagRoutes; +export const createTagRoutes = (tagController: ITagsController): Router => { + const router = Router(); + router.post("/", tagController.createTag); + router.get("/team", tagController.getTagsByTeamId); + router.get("/:id", tagController.getTagById); + router.delete("/:id", tagController.deleteTag); + router.patch("/:id", tagController.editTag); + return router; +}; diff --git a/server/src/config/routes.ts b/server/src/config/routes.ts index 855c18abb..810594354 100644 --- a/server/src/config/routes.ts +++ b/server/src/config/routes.ts @@ -5,52 +5,51 @@ import { authApiLimiter } from "../api/middleware/rateLimiter.js"; import type { InitializedControllers } from "./controllers.js"; import type { ApiServices } from "@/config/services.api.js"; -import AuthRoutes from "../api/routes/authRoute.js"; -import InviteRoutes from "../api/routes/inviteRoute.js"; -import MonitorRoutes from "../api/routes/monitorRoute.js"; -import CheckRoutes from "../api/routes/checkRoute.js"; -import GeoCheckRoutes from "../api/routes/geoCheckRoutes.js"; -import SettingsRoutes from "../api/routes/settingsRoute.js"; -import MaintenanceWindowRoutes from "../api/routes/maintenanceWindowRoute.js"; -import StatusPageRoutes from "../api/routes/statusPageRoute.js"; -import QueueRoutes from "../api/routes/queueRoute.js"; -import LogRoutes from "../api/routes/logRoutes.js"; -import DiagnosticRoutes from "../api/routes/diagnosticRoute.js"; -import NotificationRoutes from "../api/routes/notificationRoute.js"; -import TagRoutes from "../api/routes/tagRoutes.js"; - -import IncidentRoutes from "../api/routes/incidentRoute.js"; +import { createAuthRoutes } from "@/api/routes/authRoutes.js"; +import { createInviteRoutes } from "@/api/routes/inviteRoutes.js"; +import { createMonitorRoutes } from "@/api/routes/monitorRoutes.js"; +import { createCheckRoutes } from "@/api/routes/checkRoutes.js"; +import { createGeoCheckRoutes } from "@/api/routes/geoCheckRoutes.js"; +import { createSettingsRoutes } from "@/api/routes/settingsRoutes.js"; +import { createMaintenanceWindowRoutes } from "@/api/routes/maintenanceWindowRoutes.js"; +import { createQueueRoutes } from "@/api/routes/queueRoutes.js"; +import { createLogRoutes } from "@/api/routes/logRoutes.js"; +import { createStatusPageRoutes } from "@/api/routes/statusPageRoutes.js"; +import { createDiagnosticRoutes } from "@/api/routes/diagnosticRoutes.js"; +import { createNotificationRoutes } from "@/api/routes/notificationRoutes.js"; +import { createTagRoutes } from "@/api/routes/tagRoutes.js"; +import { createIncidentRoutes } from "@/api/routes/incidentRoutes.js"; export const setupRoutes = (app: Application, controllers: InitializedControllers, apiServices: ApiServices) => { const verifyJWT = createVerifyJWT(apiServices.settingsService); - const authRoutes = new AuthRoutes(controllers.authController, verifyJWT); - const monitorRoutes = new MonitorRoutes(controllers.monitorController); - const settingsRoutes = new SettingsRoutes(controllers.settingsController); - const checkRoutes = new CheckRoutes(controllers.checkController); - const geoCheckRoutes = new GeoCheckRoutes(controllers.geoCheckController); - const inviteRoutes = new InviteRoutes(controllers.inviteController, verifyJWT); - const maintenanceWindowRoutes = new MaintenanceWindowRoutes(controllers.maintenanceWindowController); - const queueRoutes = new QueueRoutes(controllers.queueController); - const logRoutes = new LogRoutes(controllers.logController); + const authRoutes = createAuthRoutes(controllers.authController, verifyJWT); + const monitorRoutes = createMonitorRoutes(controllers.monitorController); + const settingsRoutes = createSettingsRoutes(controllers.settingsController); + const checkRoutes = createCheckRoutes(controllers.checkController); + const geoCheckRoutes = createGeoCheckRoutes(controllers.geoCheckController); + const inviteRoutes = createInviteRoutes(controllers.inviteController, verifyJWT); + const maintenanceWindowRoutes = createMaintenanceWindowRoutes(controllers.maintenanceWindowController); + const queueRoutes = createQueueRoutes(controllers.queueController); + const logRoutes = createLogRoutes(controllers.logController); const verifyStatusPageAccess = createVerifyStatusPageAccess(apiServices.statusPagesRepository, verifyJWT); - const statusPageRoutes = new StatusPageRoutes(controllers.statusPageController, verifyJWT, verifyStatusPageAccess); - const notificationRoutes = new NotificationRoutes(controllers.notificationController); - const tagRoutes = new TagRoutes(controllers.tagController); - const diagnosticRoutes = new DiagnosticRoutes(controllers.diagnosticController, verifyJWT); - const incidentRoutes = new IncidentRoutes(controllers.incidentController); + const statusPageRoutes = createStatusPageRoutes(controllers.statusPageController, verifyJWT, verifyStatusPageAccess); + const notificationRoutes = createNotificationRoutes(controllers.notificationController); + const tagRoutes = createTagRoutes(controllers.tagController); + const diagnosticRoutes = createDiagnosticRoutes(controllers.diagnosticController, verifyJWT); + const incidentRoutes = createIncidentRoutes(controllers.incidentController); - app.use("/api/v1/auth", authApiLimiter, authRoutes.getRouter()); - app.use("/api/v1/monitors", verifyJWT, monitorRoutes.getRouter()); - app.use("/api/v1/settings", verifyJWT, settingsRoutes.getRouter()); - app.use("/api/v1/checks", verifyJWT, checkRoutes.getRouter()); - app.use("/api/v1/geo-checks", verifyJWT, geoCheckRoutes.getRouter()); - app.use("/api/v1/invite", inviteRoutes.getRouter()); - app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRoutes.getRouter()); - app.use("/api/v1/queue", verifyJWT, queueRoutes.getRouter()); - app.use("/api/v1/logs", verifyJWT, logRoutes.getRouter()); - app.use("/api/v1/status-page", statusPageRoutes.getRouter()); - app.use("/api/v1/notifications", verifyJWT, notificationRoutes.getRouter()); - app.use("/api/v1/tags", verifyJWT, tagRoutes.getRouter()); - app.use("/api/v1/diagnostic", verifyJWT, diagnosticRoutes.getRouter()); - app.use("/api/v1/incidents", verifyJWT, incidentRoutes.getRouter()); + app.use("/api/v1/auth", authApiLimiter, authRoutes); + app.use("/api/v1/monitors", verifyJWT, monitorRoutes); + app.use("/api/v1/settings", verifyJWT, settingsRoutes); + app.use("/api/v1/checks", verifyJWT, checkRoutes); + app.use("/api/v1/geo-checks", verifyJWT, geoCheckRoutes); + app.use("/api/v1/invite", inviteRoutes); + app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRoutes); + app.use("/api/v1/queue", verifyJWT, queueRoutes); + app.use("/api/v1/logs", verifyJWT, logRoutes); + app.use("/api/v1/status-page", statusPageRoutes); + app.use("/api/v1/notifications", verifyJWT, notificationRoutes); + app.use("/api/v1/tags", verifyJWT, tagRoutes); + app.use("/api/v1/diagnostic", verifyJWT, diagnosticRoutes); + app.use("/api/v1/incidents", verifyJWT, incidentRoutes); };