Merge pull request #2650 from bluewave-labs/fix/route-reorder

fix: reorder routes for correctness
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-07-21 09:56:50 -07:00
commit 46d7009837
10 files changed
+102 -106

No files matched your search

+6 -3
View File
@@ -38,14 +38,17 @@ const verifyJWT = (req, res, next) => {
// Verify the token's authenticity // Verify the token's authenticity
const { jwtSecret } = ServiceRegistry.get(SettingsService.SERVICE_NAME).getSettings(); const { jwtSecret } = ServiceRegistry.get(SettingsService.SERVICE_NAME).getSettings();
jwt.verify(parsedToken, jwtSecret, (err, decoded) => { jwt.verify(parsedToken, jwtSecret, (err, decoded) => {
if (err) {
if (err) { if (err) {
const errorMessage = const errorMessage =
err.name === "TokenExpiredError" err.name === "TokenExpiredError"
? stringService.expiredAuthToken ? stringService.expiredAuthToken
: stringService.invalidAuthToken; : stringService.invalidAuthToken;
return res.status(401).json({ success: false, msg: errorMessage }); err.details = { msg: errorMessage };
} err.status = 401;
err.service = SERVICE_NAME;
err.method = "verifyJWT";
next(err);
return;
} else { } else {
// Token is valid, carry on // Token is valid, carry on
req.user = decoded; req.user = decoded;
+8 -6
View File
@@ -13,23 +13,24 @@ class CheckRoutes {
} }
initRoutes() { initRoutes() {
this.router.get("/team", this.checkController.getChecksByTeam);
this.router.get("/team/summary", this.checkController.getChecksSummaryByTeamId); this.router.get("/team/summary", this.checkController.getChecksSummaryByTeamId);
this.router.get("/team", this.checkController.getChecksByTeam);
this.router.put(
"/team/ttl",
isAllowed(["admin", "superadmin"]),
this.checkController.updateChecksTTL
);
this.router.delete( this.router.delete(
"/team", "/team",
isAllowed(["admin", "superadmin"]), isAllowed(["admin", "superadmin"]),
this.checkController.deleteChecksByTeamId this.checkController.deleteChecksByTeamId
); );
this.router.put( this.router.put(
"/check/:checkId", "/check/:checkId",
verifyTeamAccess(Check, "checkId"), verifyTeamAccess(Check, "checkId"),
this.checkController.ackCheck this.checkController.ackCheck
); );
this.router.put(
"/team/ttl",
isAllowed(["admin", "superadmin"]),
this.checkController.updateChecksTTL
);
this.router.get("/:monitorId", this.checkController.getChecksByMonitor); this.router.get("/:monitorId", this.checkController.getChecksByMonitor);
this.router.post( this.router.post(
@@ -42,6 +43,7 @@ class CheckRoutes {
verifyOwnership(Monitor, "monitorId"), verifyOwnership(Monitor, "monitorId"),
this.checkController.deleteChecks this.checkController.deleteChecks
); );
this.router.put("/:path/:monitorId?", this.checkController.ackAllChecks); this.router.put("/:path/:monitorId?", this.checkController.ackAllChecks);
} }
+2 -3
View File
@@ -7,13 +7,12 @@ class DiagnosticRoutes {
this.initRoutes(); this.initRoutes();
} }
initRoutes() { initRoutes() {
this.router.post("/db/stats", this.diagnosticController.getDbStats);
this.router.get("/system", this.diagnosticController.getSystemStats);
this.router.get( this.router.get(
"/db/get-monitors-by-team-id/:teamId", "/db/get-monitors-by-team-id/:teamId",
this.diagnosticController.getMonitorsByTeamIdExecutionStats this.diagnosticController.getMonitorsByTeamIdExecutionStats
); );
this.router.post("/db/stats", this.diagnosticController.getDbStats);
this.router.get("/system", this.diagnosticController.getSystemStats);
} }
getRouter() { getRouter() {
+6 -7
View File
@@ -10,15 +10,14 @@ class InviteRoutes {
} }
initRoutes() { initRoutes() {
this.router.post(
"/",
isAllowed(["admin", "superadmin"]),
verifyJWT,
this.inviteController.getInviteToken
);
this.router.post("/send", this.inviteController.sendInviteEmail); this.router.post("/send", this.inviteController.sendInviteEmail);
this.router.post("/verify", this.inviteController.inviteVerifyController); this.router.post("/verify", this.inviteController.inviteVerifyController);
this.router.post(
"/",
verifyJWT,
isAllowed(["admin", "superadmin"]),
this.inviteController.getInviteToken
);
} }
getRouter() { getRouter() {
+7 -13
View File
@@ -6,35 +6,29 @@ import MaintenanceWindow from "../db/models/MaintenanceWindow.js";
class MaintenanceWindowRoutes { class MaintenanceWindowRoutes {
constructor(maintenanceWindowController) { constructor(maintenanceWindowController) {
this.router = Router(); this.router = Router();
this.maintenanceWindowController = maintenanceWindowController; this.mwController = maintenanceWindowController;
this.initRoutes(); this.initRoutes();
} }
initRoutes() { initRoutes() {
this.router.post("/", this.maintenanceWindowController.createMaintenanceWindows); this.router.post("/", this.mwController.createMaintenanceWindows);
this.router.get("/team/", this.mwController.getMaintenanceWindowsByTeamId);
this.router.get( this.router.get(
"/monitor/:monitorId", "/monitor/:monitorId",
verifyOwnership(Monitor, "monitorId"), verifyOwnership(Monitor, "monitorId"),
this.maintenanceWindowController.getMaintenanceWindowsByMonitorId this.mwController.getMaintenanceWindowsByMonitorId
); );
this.router.get( this.router.get("/:id", this.mwController.getMaintenanceWindowById);
"/team/",
this.maintenanceWindowController.getMaintenanceWindowsByTeamId
);
this.router.get("/:id", this.maintenanceWindowController.getMaintenanceWindowById);
this.router.put( this.router.put(
"/:id", "/:id",
verifyTeamAccess(MaintenanceWindow, "id"), verifyTeamAccess(MaintenanceWindow, "id"),
this.maintenanceWindowController.editMaintenanceWindow this.mwController.editMaintenanceWindow
); );
this.router.delete( this.router.delete(
"/:id", "/:id",
verifyTeamAccess(MaintenanceWindow, "id"), verifyTeamAccess(MaintenanceWindow, "id"),
this.maintenanceWindowController.deleteMaintenanceWindow this.mwController.deleteMaintenanceWindow
); );
} }
+52 -51
View File
@@ -17,22 +17,43 @@ class MonitorRoutes {
} }
initRoutes() { initRoutes() {
this.router.get("/", this.monitorController.getAllMonitors); // Team routes
this.router.get("/team", this.monitorController.getMonitorsByTeamId);
this.router.get(
"/team/with-checks",
this.monitorController.getMonitorsWithChecksByTeamId
);
this.router.get(
"/summary/team",
this.monitorController.getMonitorsAndSummaryByTeamId
); // TODO should be /team/summary
// Uptime routes
this.router.get("/uptime", this.monitorController.getAllMonitorsWithUptimeStats); this.router.get("/uptime", this.monitorController.getAllMonitorsWithUptimeStats);
this.router.get( this.router.get(
"/export", "/uptime/details/:monitorId",
isAllowed(["admin", "superadmin"]), this.monitorController.getUptimeDetailsById
this.monitorController.exportMonitorsToCSV
); );
this.router.get("/stats/:monitorId", this.monitorController.getMonitorStatsById);
// Hardware routes
this.router.get( this.router.get(
"/hardware/details/:monitorId", "/hardware/details/:monitorId",
this.monitorController.getHardwareDetailsById this.monitorController.getHardwareDetailsById
); );
// General monitor routes
this.router.post(
"/pause/:monitorId",
isAllowed(["admin", "superadmin"]),
this.monitorController.pauseMonitor
);
this.router.get("/stats/:monitorId", this.monitorController.getMonitorStatsById);
// Util routes
this.router.get( this.router.get(
"/uptime/details/:monitorId", "/resolution/url",
this.monitorController.getUptimeDetailsById isAllowed(["admin", "superadmin"]),
this.monitorController.checkEndpointResolution
); );
this.router.get("/certificate/:monitorId", (req, res, next) => { this.router.get("/certificate/:monitorId", (req, res, next) => {
this.monitorController.getMonitorCertificate( this.monitorController.getMonitorCertificate(
@@ -42,78 +63,58 @@ class MonitorRoutes {
fetchMonitorCertificate fetchMonitorCertificate
); );
}); });
this.router.get("/team", this.monitorController.getMonitorsByTeamId);
this.router.get("/:monitorId", this.monitorController.getMonitorById);
this.router.get(
"/summary/team",
this.monitorController.getMonitorsAndSummaryByTeamId
);
this.router.get(
"/team/with-checks",
this.monitorController.getMonitorsWithChecksByTeamId
);
this.router.get(
"/resolution/url",
isAllowed(["admin", "superadmin"]),
this.monitorController.checkEndpointResolution
);
this.router.delete(
"/:monitorId",
verifyOwnership(Monitor, "monitorId"),
isAllowed(["admin", "superadmin"]),
this.monitorController.deleteMonitor
);
// General monitor CRUD routes
this.router.get("/", this.monitorController.getAllMonitors);
this.router.post( this.router.post(
"/", "/",
isAllowed(["admin", "superadmin"]), isAllowed(["admin", "superadmin"]),
this.monitorController.createMonitor this.monitorController.createMonitor
); );
this.router.put(
"/:monitorId",
verifyTeamAccess(Monitor, "monitorId"),
isAllowed(["admin", "superadmin"]),
this.monitorController.editMonitor
);
this.router.delete( this.router.delete(
"/", "/",
isAllowed(["superadmin"]), isAllowed(["superadmin"]),
this.monitorController.deleteAllMonitors this.monitorController.deleteAllMonitors
); );
this.router.post( // Other static routes
"/pause/:monitorId",
isAllowed(["admin", "superadmin"]),
this.monitorController.pauseMonitor
);
this.router.post( this.router.post(
"/demo", "/demo",
isAllowed(["admin", "superadmin"]), isAllowed(["admin", "superadmin"]),
this.monitorController.addDemoMonitors this.monitorController.addDemoMonitors
); );
this.router.get(
"/export",
isAllowed(["admin", "superadmin"]),
this.monitorController.exportMonitorsToCSV
);
this.router.post("/seed", isAllowed(["superadmin"]), this.monitorController.seedDb);
this.router.post( this.router.post(
"/bulk", "/bulk",
isAllowed(["admin", "superadmin"]), isAllowed(["admin", "superadmin"]),
upload.single("csvFile"), upload.single("csvFile"),
this.monitorController.createBulkMonitors this.monitorController.createBulkMonitors
); );
this.router.post("/seed", isAllowed(["superadmin"]), this.monitorController.seedDb);
this.router.post( this.router.post(
"/test-email", "/test-email",
isAllowed(["admin", "superadmin"]), isAllowed(["admin", "superadmin"]),
this.monitorController.sendTestEmail this.monitorController.sendTestEmail
); );
// Individual monitor CRUD routes
this.router.get("/:monitorId", this.monitorController.getMonitorById);
this.router.put(
"/:monitorId",
verifyTeamAccess(Monitor, "monitorId"),
isAllowed(["admin", "superadmin"]),
this.monitorController.editMonitor
);
this.router.delete(
"/:monitorId",
verifyOwnership(Monitor, "monitorId"),
isAllowed(["admin", "superadmin"]),
this.monitorController.deleteMonitor
);
} }
getRouter() { getRouter() {
+3 -4
View File
@@ -13,11 +13,11 @@ class NotificationRoutes {
initializeRoutes() { initializeRoutes() {
this.router.use(verifyJWT); this.router.use(verifyJWT);
this.router.post("/test", this.notificationController.testNotification);
this.router.post("/test/all", this.notificationController.testAllNotifications);
this.router.post("/", this.notificationController.createNotification); 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("/team", this.notificationController.getNotificationsByTeamId);
this.router.delete( this.router.delete(
@@ -25,7 +25,6 @@ class NotificationRoutes {
verifyOwnership(Notification, "id"), verifyOwnership(Notification, "id"),
this.notificationController.deleteNotification this.notificationController.deleteNotification
); );
this.router.get("/:id", this.notificationController.getNotificationById); this.router.get("/:id", this.notificationController.getNotificationById);
this.router.put( this.router.put(
"/:id", "/:id",
+13 -17
View File
@@ -7,41 +7,37 @@ class QueueRoutes {
this.initRoutes(); this.initRoutes();
} }
initRoutes() { initRoutes() {
this.router.get(
"/metrics",
isAllowed(["admin", "superadmin"]),
this.queueController.getMetrics
);
this.router.get( this.router.get(
"/jobs", "/jobs",
isAllowed(["admin", "superadmin"]), isAllowed(["admin", "superadmin"]),
this.queueController.getJobs this.queueController.getJobs
); );
this.router.get(
"/all-metrics",
isAllowed(["admin", "superadmin"]),
this.queueController.getAllMetrics
);
this.router.post( this.router.post(
"/jobs", "/jobs",
isAllowed(["admin", "superadmin"]), isAllowed(["admin", "superadmin"]),
this.queueController.addJob this.queueController.addJob
); );
this.router.post( this.router.get(
"/flush", "/metrics",
isAllowed(["admin", "superadmin"]), isAllowed(["admin", "superadmin"]),
this.queueController.flushQueue this.queueController.getMetrics
); );
this.router.get( this.router.get(
"/health", "/health",
isAllowed(["admin", "superadmin"]), isAllowed(["admin", "superadmin"]),
this.queueController.checkQueueHealth this.queueController.checkQueueHealth
); );
this.router.get(
"/all-metrics",
isAllowed(["admin", "superadmin"]),
this.queueController.getAllMetrics
);
this.router.post(
"/flush",
isAllowed(["admin", "superadmin"]),
this.queueController.flushQueue
);
} }
getRouter() { getRouter() {
+2 -1
View File
@@ -13,7 +13,6 @@ class StatusPageRoutes {
initRoutes() { initRoutes() {
this.router.get("/", this.statusPageController.getStatusPage); this.router.get("/", this.statusPageController.getStatusPage);
this.router.get("/team", verifyJWT, this.statusPageController.getStatusPagesByTeamId); this.router.get("/team", verifyJWT, this.statusPageController.getStatusPagesByTeamId);
this.router.get("/:url", this.statusPageController.getStatusPageByUrl);
this.router.post( this.router.post(
"/", "/",
@@ -27,6 +26,8 @@ class StatusPageRoutes {
verifyJWT, verifyJWT,
this.statusPageController.updateStatusPage this.statusPageController.updateStatusPage
); );
this.router.get("/:url", this.statusPageController.getStatusPageByUrl);
this.router.delete("/:url(*)", verifyJWT, this.statusPageController.deleteStatusPage); this.router.delete("/:url(*)", verifyJWT, this.statusPageController.deleteStatusPage);
} }
+3 -1
View File
@@ -32,7 +32,9 @@
<p>Hello {{ name }}!</p> <p>Hello {{ name }}!</p>
<p>One of the admins created an account for you on the Checkmate server.</p> <p>One of the admins created an account for you on the Checkmate server.</p>
<p>You can go ahead and create your account using this link.</p> <p>You can go ahead and create your account using this link.</p>
<p><a href="{{link}}">{{link}}</a></p> <p>
<a href="{{link}}">{{ link }}</a>
</p>
<p>Thank you.</p> <p>Thank you.</p>
</mj-text> </mj-text>
</mj-column> </mj-column>