import { Router } from "express"; import { isAllowed } from "@/middleware/isAllowed.js"; import { IMonitorController } from "@/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); this.router.get("/team/groups", this.monitorController.getGroupsByTeamId); // 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;