From b4ffcc5555bad78ea9b6828e08934517c3761825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Kr=C3=BDda?= Date: Sat, 30 Apr 2022 15:50:05 +0200 Subject: [PATCH] Added JSDoc --- server/model/maintenance.js | 6 ++++-- server/model/monitor.js | 5 +++++ server/routers/api-router.js | 2 +- server/server.js | 5 +++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/server/model/maintenance.js b/server/model/maintenance.js index 553088959..1b0b9ee09 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 23876ac75..6587d2cd8 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 af3058097..a5a87b8c5 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 38b0babfd..b4060351a 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 = {};