2024-10-15 11:57:37 +08:00
|
|
|
import { Router } from "express";
|
|
|
|
|
import { isAllowed } from "../middleware/isAllowed.js";
|
2024-10-16 14:17:35 +08:00
|
|
|
import { fetchMonitorCertificate } from "../controllers/controllerUtils.js";
|
2024-10-15 11:57:37 +08:00
|
|
|
|
2024-12-24 11:58:56 -08:00
|
|
|
class MonitorRoutes {
|
|
|
|
|
constructor(monitorController) {
|
|
|
|
|
this.router = Router();
|
|
|
|
|
this.monitorController = monitorController;
|
|
|
|
|
this.initRoutes();
|
|
|
|
|
}
|
2024-05-21 11:23:39 -07:00
|
|
|
|
2024-12-24 11:58:56 -08:00
|
|
|
initRoutes() {
|
|
|
|
|
this.router.get("/", this.monitorController.getAllMonitors);
|
|
|
|
|
this.router.get("/uptime", this.monitorController.getAllMonitorsWithUptimeStats);
|
|
|
|
|
this.router.get("/stats/:monitorId", this.monitorController.getMonitorStatsById);
|
2024-12-31 15:05:03 -08:00
|
|
|
this.router.get(
|
|
|
|
|
"/hardware/details/:monitorId",
|
|
|
|
|
this.monitorController.getHardwareDetailsById
|
|
|
|
|
);
|
2025-01-08 13:40:57 -08:00
|
|
|
|
2024-12-30 14:56:38 -08:00
|
|
|
this.router.get(
|
|
|
|
|
"/uptime/details/:monitorId",
|
|
|
|
|
this.monitorController.getUptimeDetailsById
|
|
|
|
|
);
|
2024-12-24 11:58:56 -08:00
|
|
|
this.router.get("/certificate/:monitorId", (req, res, next) => {
|
|
|
|
|
this.monitorController.getMonitorCertificate(
|
|
|
|
|
req,
|
|
|
|
|
res,
|
|
|
|
|
next,
|
|
|
|
|
fetchMonitorCertificate
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
this.router.get("/:monitorId", this.monitorController.getMonitorById);
|
2025-01-08 13:40:57 -08:00
|
|
|
|
2024-12-24 11:58:56 -08:00
|
|
|
this.router.get("/team/:teamId", this.monitorController.getMonitorsByTeamId);
|
2024-08-27 10:39:55 -07:00
|
|
|
|
2024-12-24 11:58:56 -08:00
|
|
|
this.router.get(
|
|
|
|
|
"/resolution/url",
|
|
|
|
|
isAllowed(["admin", "superadmin"]),
|
|
|
|
|
this.monitorController.checkEndpointResolution
|
|
|
|
|
);
|
2024-08-27 10:39:55 -07:00
|
|
|
|
2024-12-24 11:58:56 -08:00
|
|
|
this.router.delete(
|
|
|
|
|
"/:monitorId",
|
|
|
|
|
isAllowed(["admin", "superadmin"]),
|
|
|
|
|
this.monitorController.deleteMonitor
|
|
|
|
|
);
|
2024-11-06 11:17:26 +08:00
|
|
|
|
2024-12-24 11:58:56 -08:00
|
|
|
this.router.post(
|
|
|
|
|
"/",
|
|
|
|
|
isAllowed(["admin", "superadmin"]),
|
|
|
|
|
this.monitorController.createMonitor
|
|
|
|
|
);
|
2024-06-18 11:42:25 -07:00
|
|
|
|
2024-12-24 11:58:56 -08:00
|
|
|
this.router.put(
|
|
|
|
|
"/:monitorId",
|
|
|
|
|
isAllowed(["admin", "superadmin"]),
|
|
|
|
|
this.monitorController.editMonitor
|
|
|
|
|
);
|
2024-08-28 15:21:59 -07:00
|
|
|
|
2024-12-24 11:58:56 -08:00
|
|
|
this.router.delete(
|
|
|
|
|
"/",
|
|
|
|
|
isAllowed(["superadmin"]),
|
|
|
|
|
this.monitorController.deleteAllMonitors
|
|
|
|
|
);
|
2024-08-28 15:21:59 -07:00
|
|
|
|
2024-12-24 11:58:56 -08:00
|
|
|
this.router.post(
|
|
|
|
|
"/pause/:monitorId",
|
|
|
|
|
isAllowed(["admin", "superadmin"]),
|
|
|
|
|
this.monitorController.pauseMonitor
|
|
|
|
|
);
|
2024-08-28 15:21:59 -07:00
|
|
|
|
2024-12-24 11:58:56 -08:00
|
|
|
this.router.post(
|
|
|
|
|
"/demo",
|
|
|
|
|
isAllowed(["admin", "superadmin"]),
|
|
|
|
|
this.monitorController.addDemoMonitors
|
|
|
|
|
);
|
2025-01-22 08:29:38 -08:00
|
|
|
|
|
|
|
|
this.router.post("/seed", isAllowed(["superadmin"]), this.monitorController.seedDb);
|
2024-12-24 11:58:56 -08:00
|
|
|
}
|
2024-09-11 11:03:39 +08:00
|
|
|
|
2024-12-24 11:58:56 -08:00
|
|
|
getRouter() {
|
|
|
|
|
return this.router;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default MonitorRoutes;
|