2025-04-20 11:29:53 -07:00
|
|
|
import { Router } from "express";
|
2026-01-21 10:36:03 -08:00
|
|
|
import { isAllowed } from "@/middleware/isAllowed.js";
|
2025-04-29 12:47:24 +05:30
|
|
|
import multer from "multer";
|
2026-01-21 10:36:03 -08:00
|
|
|
import { fetchMonitorCertificate } from "@/controllers/controllerUtils.js";
|
2025-04-29 12:47:24 +05:30
|
|
|
const upload = multer({
|
2025-05-16 15:01:34 -07:00
|
|
|
storage: multer.memoryStorage(), // Store file in memory as Buffer
|
|
|
|
|
});
|
2025-04-29 12:47:24 +05:30
|
|
|
|
2025-04-20 11:29:53 -07:00
|
|
|
class MonitorRoutes {
|
2026-01-12 22:58:46 +00:00
|
|
|
private router: Router;
|
|
|
|
|
private monitorController: any;
|
|
|
|
|
constructor(monitorController: any) {
|
2025-04-20 11:29:53 -07:00
|
|
|
this.router = Router();
|
|
|
|
|
this.monitorController = monitorController;
|
|
|
|
|
this.initRoutes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initRoutes() {
|
2025-07-21 09:55:49 -07:00
|
|
|
// Team routes
|
|
|
|
|
this.router.get("/team", this.monitorController.getMonitorsByTeamId);
|
2025-07-21 10:34:04 -07:00
|
|
|
this.router.get("/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId);
|
2025-10-12 21:11:20 -04:00
|
|
|
this.router.get("/team/groups", this.monitorController.getGroupsByTeamId);
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2025-07-21 09:55:49 -07:00
|
|
|
// Uptime routes
|
2025-07-21 10:34:04 -07:00
|
|
|
this.router.get("/uptime/details/:monitorId", this.monitorController.getUptimeDetailsById);
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2025-07-21 09:55:49 -07:00
|
|
|
// Hardware routes
|
2025-07-21 10:34:04 -07:00
|
|
|
this.router.get("/hardware/details/:monitorId", this.monitorController.getHardwareDetailsById);
|
2026-02-20 15:11:37 -08:00
|
|
|
|
2026-01-14 22:44:23 +00:00
|
|
|
// PageSpeed routes
|
|
|
|
|
this.router.get("/pagespeed/details/:monitorId", this.monitorController.getPageSpeedDetailsById);
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2026-02-24 19:19:32 +00:00
|
|
|
// Geo checks routes
|
|
|
|
|
this.router.get("/:monitorId/geo-checks", this.monitorController.getGeoChecksByMonitorId);
|
|
|
|
|
|
2025-07-21 09:55:49 -07:00
|
|
|
// General monitor routes
|
2025-07-21 10:34:04 -07:00
|
|
|
this.router.post("/pause/:monitorId", isAllowed(["admin", "superadmin"]), this.monitorController.pauseMonitor);
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2025-07-21 09:55:49 -07:00
|
|
|
// Util routes
|
|
|
|
|
this.router.get("/certificate/:monitorId", (req, res, next) => {
|
2025-07-21 10:34:04 -07:00
|
|
|
this.monitorController.getMonitorCertificate(req, res, next, fetchMonitorCertificate);
|
2025-07-21 09:55:49 -07:00
|
|
|
});
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2025-07-21 09:55:49 -07:00
|
|
|
// General monitor CRUD routes
|
2025-07-21 10:34:04 -07:00
|
|
|
this.router.post("/", isAllowed(["admin", "superadmin"]), this.monitorController.createMonitor);
|
|
|
|
|
this.router.delete("/", isAllowed(["superadmin"]), this.monitorController.deleteAllMonitors);
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2025-07-21 09:55:49 -07:00
|
|
|
// Other static routes
|
2025-07-21 10:34:04 -07:00
|
|
|
this.router.post("/demo", isAllowed(["admin", "superadmin"]), this.monitorController.addDemoMonitors);
|
2025-11-21 10:43:29 -08:00
|
|
|
this.router.get("/export/json", isAllowed(["admin", "superadmin"]), this.monitorController.exportMonitorsToJSON);
|
2026-02-21 03:43:11 +00:00
|
|
|
this.router.post("/import/json", isAllowed(["admin", "superadmin"]), this.monitorController.importMonitorsFromJSON);
|
2026-02-20 15:11:37 -08:00
|
|
|
|
2025-08-06 00:53:35 +03:00
|
|
|
this.router.get("/games", this.monitorController.getAllGames);
|
2025-07-21 09:55:49 -07:00
|
|
|
|
|
|
|
|
// Individual monitor CRUD routes
|
|
|
|
|
this.router.get("/:monitorId", this.monitorController.getMonitorById);
|
2026-01-30 19:43:34 +00:00
|
|
|
this.router.patch("/:monitorId", isAllowed(["admin", "superadmin"]), this.monitorController.editMonitor);
|
2025-07-21 13:58:01 -07:00
|
|
|
this.router.delete("/:monitorId", isAllowed(["admin", "superadmin"]), this.monitorController.deleteMonitor);
|
2025-04-20 11:29:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getRouter() {
|
|
|
|
|
return this.router;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default MonitorRoutes;
|