Add get monitor stats by ID to docs
This commit is contained in:
1 parent
8cccc58d39
commit
bd03964ab6
4 files changed
+54
-53
No files matched your search
@@ -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<Express.Response>}
|
|
||||||
* @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
|
* Returns monitor stats for monitor with matching ID
|
||||||
* @async
|
* @async
|
||||||
@@ -516,7 +474,6 @@ const addDemoMonitors = async (req, res, next) => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getAllMonitors,
|
getAllMonitors,
|
||||||
getMonitorAggregateStats,
|
|
||||||
getMonitorStatsById,
|
getMonitorStatsById,
|
||||||
getMonitorCertificate,
|
getMonitorCertificate,
|
||||||
getMonitorById,
|
getMonitorById,
|
||||||
|
|||||||
@@ -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": {
|
"components": {
|
||||||
"securitySchemes": {
|
"securitySchemes": {
|
||||||
"bearerAuth": {
|
"bearerAuth": {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const monitorController = require("../controllers/monitorController");
|
|||||||
const { isAllowed } = require("../middleware/isAllowed");
|
const { isAllowed } = require("../middleware/isAllowed");
|
||||||
|
|
||||||
router.get("/", monitorController.getAllMonitors);
|
router.get("/", monitorController.getAllMonitors);
|
||||||
router.get("/aggregate/:monitorId", monitorController.getMonitorAggregateStats);
|
|
||||||
router.get("/stats/:monitorId", monitorController.getMonitorStatsById);
|
router.get("/stats/:monitorId", monitorController.getMonitorStatsById);
|
||||||
router.get("/certificate/:monitorId", monitorController.getMonitorCertificate);
|
router.get("/certificate/:monitorId", monitorController.getMonitorCertificate);
|
||||||
router.get("/:monitorId", monitorController.getMonitorById);
|
router.get("/:monitorId", monitorController.getMonitorById);
|
||||||
|
|||||||
@@ -235,13 +235,6 @@ const pauseMonitorParamValidation = joi.object({
|
|||||||
monitorId: joi.string().required(),
|
monitorId: joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const getMonitorAggregateStatsParamValidation = joi.object({
|
|
||||||
monitorId: joi.string().required(),
|
|
||||||
});
|
|
||||||
const getMonitorAggregateStatsQueryValidation = joi.object({
|
|
||||||
dateRange: joi.string().valid("day", "week", "month"),
|
|
||||||
});
|
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
// Alerts
|
// Alerts
|
||||||
//****************************************
|
//****************************************
|
||||||
@@ -407,8 +400,6 @@ module.exports = {
|
|||||||
getMonitorStatsByIdParamValidation,
|
getMonitorStatsByIdParamValidation,
|
||||||
getMonitorStatsByIdQueryValidation,
|
getMonitorStatsByIdQueryValidation,
|
||||||
getCertificateParamValidation,
|
getCertificateParamValidation,
|
||||||
getMonitorAggregateStatsParamValidation,
|
|
||||||
getMonitorAggregateStatsQueryValidation,
|
|
||||||
editMonitorBodyValidation,
|
editMonitorBodyValidation,
|
||||||
pauseMonitorParamValidation,
|
pauseMonitorParamValidation,
|
||||||
editUserParamValidation,
|
editUserParamValidation,
|
||||||
|
|||||||
Reference in new issue
Block a user