diff --git a/server/model/maintenance.js b/server/model/maintenance.js index 55308895..1b0b9ee0 100644 --- a/server/model/maintenance.js +++ b/server/model/maintenance.js @@ -8,8 +8,9 @@ const { BeanModel } = require("redbean-node/dist/bean-model"); class Maintenance extends BeanModel { /** - * Return a object that ready to parse to JSON for public + * Return an object that ready to parse to JSON for public * Only show necessary data to public + * @returns {Object} */ async toPublicJSON() { return { @@ -22,7 +23,8 @@ class Maintenance extends BeanModel { } /** - * Return a object that ready to parse to JSON + * Return an object that ready to parse to JSON + * @returns {Object} */ async toJSON() { return { diff --git a/server/model/monitor.js b/server/model/monitor.js index 23876ac7..6587d2cd 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -947,6 +947,11 @@ class Monitor extends BeanModel { ]); } + /** + * Check if monitor is under maintenance + * @param {number} monitorID ID of monitor to check + * @returns {Promise} + */ static async isUnderMaintenance(monitorID) { const maintenance = await R.getRow("SELECT COUNT(*) AS count FROM monitor_maintenance mm JOIN maintenance ON mm.maintenance_id = maintenance.id WHERE mm.monitor_id = ? AND datetime(maintenance.start_date) <= datetime('now') AND datetime(maintenance.end_date) >= datetime('now') LIMIT 1", [ monitorID ]); return maintenance.count !== 0; diff --git a/server/routers/api-router.js b/server/routers/api-router.js index af305809..a5a87b8c 100644 --- a/server/routers/api-router.js +++ b/server/routers/api-router.js @@ -156,7 +156,7 @@ router.get("/api/status-page/:slug", cache("5 minutes"), async (request, respons } }); -// TODO: make slug aware + // Status Page - Maintenance List async function getMaintenanceList() { try { diff --git a/server/server.js b/server/server.js index 38b0babf..b4060351 100644 --- a/server/server.js +++ b/server/server.js @@ -1740,6 +1740,11 @@ async function afterLogin(socket, user) { } } +/** + * Get a list of maintenances for the given user. + * @param {string} userID - The ID of the user to get maintenances for. + * @returns {Promise} A promise that resolves to an object with maintenance IDs as keys and maintenances objects as values. + */ async function getMaintenanceJSONList(userID) { let result = {};