From bd03964ab6b66eb088ff46d54e6aecedb2f78b36 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 24 Sep 2024 15:20:45 +0800 Subject: [PATCH] Add get monitor stats by ID to docs --- Server/controllers/monitorController.js | 43 -------------------- Server/openapi.json | 54 +++++++++++++++++++++++++ Server/routes/monitorRoute.js | 1 - Server/validation/joi.js | 9 ----- 4 files changed, 54 insertions(+), 53 deletions(-) diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index f5bd98b74..e534e0f60 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -44,48 +44,6 @@ const getAllMonitors = async (req, res, next) => { } }; -/** - * Returns agregate stats for a monitor - * @async - * @param {Express.Request} req - * @param {Express.Response} res - * @returns {Promise} - * @throws {Error} - */ - -const getMonitorAggregateStats = async (req, res, next) => { - try { - await getMonitorAggregateStatsParamValidation.validateAsync(req.params); - await getMonitorAggregateStatsQueryValidation.validateAsync(req.query); - } catch (error) { - error.status = 422; - error.message = - error.details?.[0]?.message || error.message || "Validation Error"; - next(error); - return; - } - - try { - const { monitorId } = req.params; - const dateRange = req.query.dateRange; - const aggregateStats = await req.db.getMonitorAggregateStats( - monitorId, - dateRange - ); - return res.json({ - success: true, - msg: successMessages.MONTIOR_STATS_BY_ID, - data: aggregateStats, - }); - } catch (error) { - error.service === undefined ? (error.service = SERVICE_NAME) : null; - error.method === undefined - ? (error.method = "getMonitorAggregateStats") - : null; - next(error); - } -}; - /** * Returns monitor stats for monitor with matching ID * @async @@ -516,7 +474,6 @@ const addDemoMonitors = async (req, res, next) => { module.exports = { getAllMonitors, - getMonitorAggregateStats, getMonitorStatsById, getMonitorCertificate, getMonitorById, diff --git a/Server/openapi.json b/Server/openapi.json index da4ba7d53..a4129a8ba 100644 --- a/Server/openapi.json +++ b/Server/openapi.json @@ -738,8 +738,62 @@ } ] } + }, + "/monitors/stats/{monitorId}": { + "get": { + "tags": ["monitors"], + "description": "Get monitor stats", + "parameters": [ + { + "name": "monitorId", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SuccessResponse" + } + } + } + }, + "422": { + "description": "Unprocessable Content", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + } } }, + "components": { "securitySchemes": { "bearerAuth": { diff --git a/Server/routes/monitorRoute.js b/Server/routes/monitorRoute.js index c6bec5f0f..aaa9c10e9 100644 --- a/Server/routes/monitorRoute.js +++ b/Server/routes/monitorRoute.js @@ -3,7 +3,6 @@ const monitorController = require("../controllers/monitorController"); const { isAllowed } = require("../middleware/isAllowed"); router.get("/", monitorController.getAllMonitors); -router.get("/aggregate/:monitorId", monitorController.getMonitorAggregateStats); router.get("/stats/:monitorId", monitorController.getMonitorStatsById); router.get("/certificate/:monitorId", monitorController.getMonitorCertificate); router.get("/:monitorId", monitorController.getMonitorById); diff --git a/Server/validation/joi.js b/Server/validation/joi.js index 60356332e..f61432595 100644 --- a/Server/validation/joi.js +++ b/Server/validation/joi.js @@ -235,13 +235,6 @@ const pauseMonitorParamValidation = joi.object({ monitorId: joi.string().required(), }); -const getMonitorAggregateStatsParamValidation = joi.object({ - monitorId: joi.string().required(), -}); -const getMonitorAggregateStatsQueryValidation = joi.object({ - dateRange: joi.string().valid("day", "week", "month"), -}); - //**************************************** // Alerts //**************************************** @@ -407,8 +400,6 @@ module.exports = { getMonitorStatsByIdParamValidation, getMonitorStatsByIdQueryValidation, getCertificateParamValidation, - getMonitorAggregateStatsParamValidation, - getMonitorAggregateStatsQueryValidation, editMonitorBodyValidation, pauseMonitorParamValidation, editUserParamValidation,