From 6437e8e9bf54b55a4e51151e77c75b67e89bf6d9 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 29 May 2024 10:59:29 -0700 Subject: [PATCH 1/9] implemented DB operations for Checks --- Server/controllers/checkController.js | 62 +++++++++++++++++++++++---- Server/db/MongoDB.js | 48 +++++++++++---------- Server/validation/joi.js | 58 +++++++++++++++++++++---- 3 files changed, 127 insertions(+), 41 deletions(-) diff --git a/Server/controllers/checkController.js b/Server/controllers/checkController.js index ef1a1a071..7734da45b 100644 --- a/Server/controllers/checkController.js +++ b/Server/controllers/checkController.js @@ -1,29 +1,73 @@ -var jwt = require("jsonwebtoken"); +const { + createCheckParamValidation, + createCheckBodyValidation, + getChecksParamValidation, + deleteChecksParamValidation, +} = require("../validation/joi"); const SERVICE_NAME = "check"; -const createCheck = (req, res, next) => { +const createCheck = async (req, res, next) => { try { - req.db.createCheck(req, res); + await createCheckParamValidation.validateAsync(req.params); + await createCheckBodyValidation.validateAsync(req.body); + } catch (error) { + error.status = 422; + error.service = SERVICE_NAME; + error.message = error.details[0].message; + next(error); + return; + } + + try { + const checkData = { ...req.body }; + const check = await req.db.createCheck(checkData); + return res + .status(200) + .json({ success: true, msg: "Check created", data: check }); } catch (error) { error.service = SERVICE_NAME; next(error); } }; -const getChecks = (req, res, next) => { +const getChecks = async (req, res, next) => { try { - req.db.getChecks(req, res); - // Return all checks for a monitor + await getChecksParamValidation.validateAsync(req.params); + } catch (error) { + error.status = 422; + error.service = SERVICE_NAME; + error.message = error.details[0].message; + next(error); + return; + } + + try { + const checks = await req.db.getChecks(req.params.monitorId); + return res + .status(200) + .json({ success: true, msg: "Checks retrieved", data: checks }); } catch (error) { error.service = SERVICE_NAME; next(error); } }; -const deleteChecks = (req, res, next) => { +const deleteChecks = async (req, res, next) => { try { - req.db.deleteChecks(req, res); - // Delete all checks for a monitor + await deleteChecksParamValidation.validateAsync(req.params); + } catch (error) { + error.status = 422; + error.service = SERVICE_NAME; + error.message = error.details[0].message; + next(error); + return; + } + + try { + const deletedCount = await req.db.deleteChecks(req.params.monitorId); + return res + .status(200) + .json({ success: true, msg: "Checks deleted", data: { deletedCount } }); } catch (error) { error.service = SERVICE_NAME; next(error); diff --git a/Server/db/MongoDB.js b/Server/db/MongoDB.js index 32d5d33f7..cc73f060d 100644 --- a/Server/db/MongoDB.js +++ b/Server/db/MongoDB.js @@ -1,6 +1,7 @@ const Monitor = require("../models/Monitor"); const mongoose = require("mongoose"); const UserModel = require("../models/user"); +const Check = require("../models/Check"); const verifyId = (userId, monitorId) => { return userId.toString() === monitorId.toString(); @@ -209,17 +210,20 @@ const editMonitor = async (req, res) => { /** * Create a check for a monitor * @async - * @param {Express.Request} req - * @param {Express.Response} res + * @param {Object} checkData + * @param {string} checkData.monitorId + * @param {boolean} checkData.status + * @param {number} checkData.responseTime + * @param {number} checkData.statusCode + * @param {string} checkData.message + * @returns {Promise} * @throws {Error} */ -const createCheck = async (req, res) => { +const createCheck = async (checkData) => { try { - // Create check with monitor id - res - .status(200) - .json({ success: true, msg: "Create check", data: req.params.monitorId }); + const check = await new Check({ ...checkData }).save(); + return check; } catch (error) { throw error; } @@ -228,17 +232,15 @@ const createCheck = async (req, res) => { /** * Get all checks for a monitor * @async - * @param {Express.Request} req - * @param {Express.Response} res + * @param {string} monitorId + * @returns {Promise>} * @throws {Error} */ -const getChecks = async (req, res) => { +const getChecks = async (monitorId) => { try { - // TODO get all checks for a monitor from DB - res - .status(200) - .json({ success: true, msg: "Get checks", data: req.params.monitorId }); + const checks = await Check.find({ monitorId }); + return checks; } catch (error) { throw error; } @@ -247,19 +249,19 @@ const getChecks = async (req, res) => { /** * Delete all checks for a monitor * @async - * @param {Express.Request} req - * @param {Express.Response} res + * @param {string} monitorId + * @returns {boolean} * @throws {Error} */ -const deleteChecks = async (req, res) => { +const deleteChecks = async (monitorId) => { try { - // TODO Delete all checks for a monitor - res.status(200).json({ - success: true, - msg: "Deleted checks", - data: req.params.monitorId, - }); + const result = await Check.deleteMany({ monitorId }); + if (result.deletedCount > 0) { + return result.deletedCount; + } else { + throw new Error(`No checks found for monitor with id ${monitorId}`); + } } catch (error) { throw error; } diff --git a/Server/validation/joi.js b/Server/validation/joi.js index 01a0d0ada..75cd48cd1 100644 --- a/Server/validation/joi.js +++ b/Server/validation/joi.js @@ -1,5 +1,9 @@ const joi = require("joi"); +//**************************************** +// Auth +//**************************************** + const loginValidation = joi.object({ email: joi.string().email().required(), password: joi.string().min(8).required(), @@ -11,6 +15,20 @@ const registerValidation = joi.object({ password: joi.string().min(8).required(), }); +const editUserParamValidation = joi.object({ + userId: joi.string().required(), +}); + +const editUserBodyValidation = joi.object({ + firstname: joi.string(), + lastname: joi.string(), + profilePicUrl: joi.string(), +}); + +//**************************************** +// Monitors +//**************************************** + const getMonitorByIdValidation = joi.object({ monitorId: joi.string().required(), }); @@ -29,15 +47,9 @@ const monitorValidation = joi.object({ interval: joi.number(), }); -const editUserParamValidation = joi.object({ - userId: joi.string().required(), -}); - -const editUserBodyValidation = joi.object({ - firstname: joi.string(), - lastname: joi.string(), - profilePicUrl: joi.string(), -}); +//**************************************** +// Alerts +//**************************************** const createAlertParamValidation = joi.object({ monitorId: joi.string().required(), @@ -80,6 +92,30 @@ const deleteAlertParamValidation = joi.object({ alertId: joi.string().required(), }); +//**************************************** +// Checks +//**************************************** + +const createCheckParamValidation = joi.object({ + monitorId: joi.string().required(), +}); + +const createCheckBodyValidation = joi.object({ + monitorId: joi.string().required(), + status: joi.boolean().required(), + responseTime: joi.number().required(), + statusCode: joi.number().required(), + message: joi.string().required(), +}); + +const getChecksParamValidation = joi.object({ + monitorId: joi.string().required(), +}); + +const deleteChecksParamValidation = joi.object({ + monitorId: joi.string().required(), +}); + module.exports = { loginValidation, registerValidation, @@ -96,4 +132,8 @@ module.exports = { editAlertParamValidation, editAlertBodyValidation, deleteAlertParamValidation, + createCheckParamValidation, + createCheckBodyValidation, + getChecksParamValidation, + deleteChecksParamValidation, }; From 247153a133cf90bf9f25351f7858a5fcc9a5f14a Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 29 May 2024 11:07:17 -0700 Subject: [PATCH 2/9] Updated readme --- README.md | 97 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index dfc57064d..80c950307 100644 --- a/README.md +++ b/README.md @@ -655,22 +655,54 @@ curl --request POST \ ###### Response Payload -> | Type | Notes | -> | ---- | ------------------- | -> | None | No payload returned | +> | Type | Notes | +> | ------- | --------------------------- | +> | `Check` | Returns newly created check | ###### Body +> | Name | Type | Notes | +> | ------------ | --------- | -------------------------------------- | +> | monitorId | `string` | Monitor associated with Check | +> | status | `boolean` | `true` for up and `false` for down | +> | responseTime | `number` | How long it took the server to respond | +> | statusCode | `number` | HTTP Status code of response | +> | message | `string` | | + ##### Sample CURL request ``` - +curl --request POST \ + --url http://localhost:5000/api/v1/checks/66562414035c4ce6a8a610ac \ + --header 'Authorization: ' \ + --header 'Content-Type: application/json' \ + --data '{ + "monitorId": "66562414035c4ce6a8a610ac", + "status": true, + "responseTime": 1, + "statusCode": 200, + "message": "good" +}' ``` ###### Sample Response ```json - +{ + "success": true, + "msg": "Check created", + "data": { + "monitorId": "66562414035c4ce6a8a610ac", + "status": true, + "responseTime": 1, + "statusCode": 200, + "message": "good", + "_id": "66576decba9f70148ea1f354", + "createdAt": "2024-05-29T18:03:24.445Z", + "updatedAt": "2024-05-29T18:03:24.445Z", + "__v": 0 + } +} ``` @@ -682,7 +714,7 @@ curl --request POST \ > | Method/Headers | Value | > | -------------- | ----- | -> | Method | POST | +> | Method | GET | ###### Response Payload @@ -693,13 +725,42 @@ curl --request POST \ ##### Sample CURL request ``` - +curl --request GET \ + --url http://localhost:5000/api/v1/checks/66562414035c4ce6a8a610ac \ + --header 'Authorization: ' \ ``` ###### Sample Response ```json - +{ + "success": true, + "msg": "Checks retrieved", + "data": [ + { + "_id": "66576c0194e11c0d4409d3c1", + "monitorId": "66562414035c4ce6a8a610ac", + "status": true, + "responseTime": 1, + "statusCode": 200, + "message": "good", + "createdAt": "2024-05-29T17:55:13.581Z", + "updatedAt": "2024-05-29T17:55:13.581Z", + "__v": 0 + }, + { + "_id": "66576c0994e11c0d4409d3c5", + "monitorId": "66562414035c4ce6a8a610ac", + "status": true, + "responseTime": 2, + "statusCode": 200, + "message": "good", + "createdAt": "2024-05-29T17:55:21.127Z", + "updatedAt": "2024-05-29T17:55:21.127Z", + "__v": 0 + } + ] +} ``` @@ -715,22 +776,28 @@ curl --request POST \ ###### Response Payload -> | Type | Notes | -> | ---- | ------------------- | -> | None | No payload returned | - -###### Body +> | Type | Notes | +> | -------- | -------------------------------------------------------------------- | +> | `Object` | `{deletedCount: n}` Returns an object showing how many items deleted | ##### Sample CURL request ``` - +curl --request POST \ + --url http://localhost:5000/api/v1/checks/delete/66562414035c4ce6a8a610ac \ + --header 'Authorization: ' \ ``` ###### Sample Response ```json - +{ + "success": true, + "msg": "Checks deleted", + "data": { + "deletedCount": 3 + } +} ``` From 879d2337b6e2eedcc0d5e71896b582ac40ded7af Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 29 May 2024 12:12:56 -0700 Subject: [PATCH 3/9] Added alert DB operations --- Server/controllers/alertController.js | 84 +++++++++++++++++----- Server/db/MongoDB.js | 100 +++++++++++++------------- 2 files changed, 117 insertions(+), 67 deletions(-) diff --git a/Server/controllers/alertController.js b/Server/controllers/alertController.js index 91bb56971..f0c3df5dd 100644 --- a/Server/controllers/alertController.js +++ b/Server/controllers/alertController.js @@ -11,6 +11,7 @@ const { editAlertBodyValidation, deleteAlertParamValidation, } = require("../validation/joi"); +const { get } = require("mongoose"); const SERVICE_NAME = "alerts"; @@ -35,7 +36,11 @@ const createAlert = async (req, res, next) => { } try { - req.db.createAlert(req, res); + const alertData = { ...req.body }; + const alert = await req.db.createAlert(alertData); + return res + .status(200) + .json({ success: true, msg: "Alert created", data: alert }); } catch (error) { error.service = SERVICE_NAME; next(error); @@ -62,7 +67,10 @@ const getAlertsByUserId = async (req, res, next) => { } try { - req.db.getAlertsByUserId(req, res); + const alerts = await req.db.getAlertsByUserId(req.params.userId); + return res + .status(200) + .json({ success: true, msg: "Got alerts", data: alerts }); } catch (error) { error.service = SERVICE_NAME; next(error); @@ -72,29 +80,30 @@ const getAlertsByUserId = async (req, res, next) => { const getAlertsByMonitorId = async (req, res, next) => { try { await getAlertsByMonitorIdParamValidation.validateAsync(req.params); - res.status(200).json({ - success: true, - msg: "Get Alerts By MonitorID", - data: req.params.monitorId, - }); } catch (error) { error.status = 422; - res.status(200).json({ success: true, msg: "Edit alert" }); - error.message = error.details[0].message; error.service = SERVICE_NAME; next(error); return; } + + try { + const alerts = await req.db.getAlertsByMonitorId(req.params.monitorId); + return res.status(200).json({ + success: true, + msg: "Got alerts by Monitor", + data: alerts, + }); + } catch (error) { + error.service = SERVICE_NAME; + next(error); + } }; + const getAlertById = async (req, res, next) => { try { await getAlertByIdParamValidation.validateAsync(req.params); - res.status(200).json({ - success: true, - msg: "Get Alert By alertID", - data: req.params.alertId, - }); } catch (error) { error.status = 422; error.message = error.details[0].message; @@ -102,24 +111,49 @@ const getAlertById = async (req, res, next) => { next(error); return; } + + try { + const alert = await req.db.getAlertById(req.params.alertId); + return res.status(200).json({ + success: true, + msg: "Got Alert By alertID", + data: alert, + }); + } catch (error) { + error.service = SERVICE_NAME; + next(error); + } }; + const editAlert = async (req, res, next) => { try { - await editAlertParamValidation(req.params); - await editAlertBodyValidation(req.body); - res.status(200).json({ success: true, msg: "Edit alert" }); + await editAlertParamValidation.validateAsync(req.params); + await editAlertBodyValidation.validateAsync(req.body); } catch (error) { + console.log(error); error.status = 422; error.message = error.details[0].message; error.service = SERVICE_NAME; next(error); return; } + + try { + const alertData = { ...req.body }; + const alert = await req.db.editAlert(req.params.alertId, alertData); + return res.status(200).json({ + success: true, + msg: "Edited alert", + data: alert, + }); + } catch (error) { + error.service = SERVICE_NAME; + next(error); + } }; const deleteAlert = async (req, res, next) => { try { - await deleteAlertParamValidation(req.params); - res.status(200).json({ success: true, msg: "Delete alert" }); + await deleteAlertParamValidation.validateAsync(req.params); } catch (error) { error.status = 422; error.message = error.details[0].message; @@ -127,6 +161,18 @@ const deleteAlert = async (req, res, next) => { next(error); return; } + + try { + const deleted = await req.db.deleteAlert(req.params.alertId); + return res.status(200).json({ + success: true, + msg: "Deleted alert", + data: deleted, + }); + } catch (error) { + error.service = SERVICE_NAME; + next(error); + } }; module.exports = { diff --git a/Server/db/MongoDB.js b/Server/db/MongoDB.js index cc73f060d..f8ea2bead 100644 --- a/Server/db/MongoDB.js +++ b/Server/db/MongoDB.js @@ -2,6 +2,7 @@ const Monitor = require("../models/Monitor"); const mongoose = require("mongoose"); const UserModel = require("../models/user"); const Check = require("../models/Check"); +const Alert = require("../models/Alert"); const verifyId = (userId, monitorId) => { return userId.toString() === monitorId.toString(); @@ -60,10 +61,6 @@ const getUserByEmail = async (req, res) => { } }; -//**************************************** -// Monitors -//**************************************** - /** * Update a user by ID * @async @@ -89,6 +86,10 @@ const updateUser = async (req, res) => { } }; +//**************************************** +// Monitors +//**************************************** + /** * Get all monitors * @async @@ -222,6 +223,7 @@ const editMonitor = async (req, res) => { const createCheck = async (checkData) => { try { + console.log(checkData); const check = await new Check({ ...checkData }).save(); return check; } catch (error) { @@ -274,16 +276,21 @@ const deleteChecks = async (monitorId) => { /** * Creates an Alert associated with a Monitor and User * @async - * @param {Express.Request} req - * @param {Express.Response} res + * @param {Object} alertData + * @param {string} alertData.checkId + * @param {string} alert.monitorId + * @param {string} alert.userId + * @param {boolean} alert.status + * @param {string} alert.message + * @param {boolean} alert.notifiedStatus + * @param {boolean} alert.acknowledgeStatus * @returns {>} * @throws {Error} */ -const createAlert = async (req, res) => { +const createAlert = async (alertData) => { try { - res - .status(200) - .json({ success: true, msg: "Create Alert", data: req.params.monitorId }); + const alert = await new Alert({ ...alertData }).save(); + return alert; } catch (error) { throw error; } @@ -292,18 +299,14 @@ const createAlert = async (req, res) => { /** * Gets all alerts a User has set * @async - * @param {Express.Request} req - * @param {Express.Response} res + * @param {string} userId * @returns {>} * @throws {Error} */ -const getAlertsByUserId = async (req, res) => { +const getAlertsByUserId = async (userId) => { try { - res.status(200).json({ - success: true, - msg: "Get Alerts By UserID", - data: req.params.userId, - }); + const alerts = await Alert.find({ userId }); + return alerts; } catch (error) { throw error; } @@ -312,73 +315,74 @@ const getAlertsByUserId = async (req, res) => { /** * Gets all alerts a for an associated Monitor * @async - * @param {Express.Request} req - * @param {Express.Response} res + * @param {string} monitorId * @returns {>} * @throws {Error} */ -const getAlertsByMonitorId = async (req, res) => { +const getAlertsByMonitorId = async (monitorId) => { try { - res.status(200).json({ - success: true, - msg: "Get Alerts By MonitorID", - data: req.params.monitorId, - }); + const alerts = await Alert.find({ monitorId }); + return alerts; } catch (error) { throw error; } }; /** - * Gets an alert with specified ID + * Returns an alert with specified ID * @async - * @param {Express.Request} req - * @param {Express.Response} res + * @param {string} alertId * @returns {Promise} * @throws {Error} */ -const getAlertById = async (req, res) => { +const getAlertById = async (alertId) => { try { - res.status(200).json({ - success: true, - msg: "Get Alert By alertID", - data: req.params.alertId, - }); + const alert = await Alert.findById(alertId); + return alert; } catch (error) { throw error; } }; /** - * Returns an edited monitor with the specified ID + * Returns an edited alert with the specified ID * @async - * @param {Express.Request} req + * @param {string} alertId + * @param {Object} alertData + * @param {string} alertData.checkId + * @param {string} alertData.monitorId + * @param {string} alertData.userId + * @param {boolean} alertData.status + * @param {string} alertData.message + * @param {boolean} alertData.notifiedStatus + * @param {boolean} alertData.acknowledgeStatus * @param {Express.Response} res * @returns {Promise>} * @throws {Error} */ -const editAlert = async (req, res) => { +const editAlert = async (alertId, alertData) => { try { - res - .status(200) - .json({ success: true, msg: "Edit alert", data: req.params.alertId }); + const editedAlert = await Alert.findByIdAndUpdate(alertId, alertData, { + new: true, + }); + return editedAlert; } catch (error) { throw error; } }; /** - * Deletes a monitor with the specified ID + * Deletes an alert with the specified ID * @async - * @param {Express.Request} req - * @param {Express.Response} res + * @param {string} alertId * @throws {Error} */ -const deleteAlert = async (req, res) => { +const deleteAlert = async (alertId) => { try { - res - .status(200) - .json({ success: true, msg: "Delete alert", data: req.params.alertId }); + const result = await Alert.findByIdAndDelete(alertId); + if (result) { + return result; + } else throw new Error(`Alert with id ${alertId} not found`); } catch (error) { throw error; } From 5fc4b018f98474e7e5d8cfad07b872d73f37d6e3 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 29 May 2024 12:15:59 -0700 Subject: [PATCH 4/9] Fixed return type for deleteChecks --- Server/db/MongoDB.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/db/MongoDB.js b/Server/db/MongoDB.js index cc73f060d..a410e7dfa 100644 --- a/Server/db/MongoDB.js +++ b/Server/db/MongoDB.js @@ -250,7 +250,7 @@ const getChecks = async (monitorId) => { * Delete all checks for a monitor * @async * @param {string} monitorId - * @returns {boolean} + * @returns {number} * @throws {Error} */ From c6f0fcb13a1eec7ae2d22b0c4ff49cec3e6b5389 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 29 May 2024 12:30:13 -0700 Subject: [PATCH 5/9] Updated documentation --- README.md | 160 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 142 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 80c950307..ff5190652 100644 --- a/README.md +++ b/README.md @@ -823,6 +823,24 @@ curl --request POST \ ###### Body + "checkId": "66577a3fd16dcf7c1ce35148", + "monitorId": "6657789ebf6766ee8e2d2edb", + "userId": "6654d1a2634754f789e1f115", + "status": false, + "message": "This is a test alert", + "notifiedStatus": "false", + "acknowledgeStatus": false + +> | Name | Type | Notes | +> | ----------------- | --------- | --------------------------------------- | +> | checkId | `string` | Id of `Check` associated with `Alert` | +> | monitorId | `string` | Id of `Monitor` associated with `Alert` | +> | userId | `string` | Id of `User` associated with `Alert` | +> | status | `boolean` | Status of `Alert` | +> | message | `string` | `Alert` message | +> | notifiedStatus | `boolean` | | +> | acknowledgeStatus | `boolean` | | + ##### Sample CURL request ``` @@ -855,13 +873,33 @@ curl --request POST \ ##### Sample CURL request ``` - +curl --request GET \ + --url http://localhost:5000/api/v1/alerts/user/6654d1a2634754f789e1f115 \ + --header 'Authorization: ' ``` ###### Sample Response ```json - +{ + "success": true, + "msg": "Got alerts", + "data": [ + { + "_id": "6657813d809adfded891a6b7", + "checkId": "66577a3fd16dcf7c1ce35148", + "monitorId": "6657789ebf6766ee8e2d2edb", + "userId": "6654d1a2634754f789e1f115", + "status": false, + "message": "This is a test alert", + "notifiedStatus": false, + "acknowledgeStatus": false, + "createdAt": "2024-05-29T19:25:49.317Z", + "updatedAt": "2024-05-29T19:25:49.317Z", + "__v": 0 + } + ] +} ``` @@ -883,13 +921,33 @@ curl --request POST \ ##### Sample CURL request ``` - +curl --request GET \ + --url http://localhost:5000/api/v1/alerts/monitor/6657789ebf6766ee8e2d2edb \ + --header 'Authorization: ' \ ``` ###### Sample Response ```json - +{ + "success": true, + "msg": "Got alerts by Monitor", + "data": [ + { + "_id": "6657813d809adfded891a6b7", + "checkId": "66577a3fd16dcf7c1ce35148", + "monitorId": "6657789ebf6766ee8e2d2edb", + "userId": "6654d1a2634754f789e1f115", + "status": false, + "message": "This is a test alert", + "notifiedStatus": false, + "acknowledgeStatus": false, + "createdAt": "2024-05-29T19:25:49.317Z", + "updatedAt": "2024-05-29T19:25:49.317Z", + "__v": 0 + } + ] +} ``` @@ -912,13 +970,31 @@ curl --request POST \ ##### Sample CURL request ``` - +curl --request GET \ + --url http://localhost:5000/api/v1/alerts/66577ddae5ff3c91437d0887 \ + --header 'Authorization: ' \ ``` ###### Sample Response ```json - +{ + "success": true, + "msg": "Got Alert By alertID", + "data": { + "_id": "66577ddae5ff3c91437d0887", + "checkId": "66577a3fd16dcf7c1ce35148", + "monitorId": "6657789ebf6766ee8e2d2edb", + "userId": "6654d1a2634754f789e1f115", + "status": false, + "message": "This is a test alert", + "notifiedStatus": false, + "acknowledgeStatus": false, + "createdAt": "2024-05-29T19:11:22.205Z", + "updatedAt": "2024-05-29T19:11:22.205Z", + "__v": 0 + } +} ``` @@ -934,22 +1010,54 @@ curl --request POST \ ###### Response Payload -> | Type | Notes | -> | ------- | -------------------- | -> | `Alert` | Returns edited alert | +> | Type | Notes | +> | ------- | ---------------------- | +> | `Alert` | Returns edited `Alert` | ###### Body +> | Name | Type | Notes | +> | ----------------- | --------- | ------------------------------------------ | +> | checkId | `string` | ID of `Check` associated with `Alert` | +> | monitorId | `string` | ID of `Monitor` id associated with `Alert` | +> | userId | `string` | ID of `User` associated with `Alert` | +> | status | `boolean` | Alert status | +> | message | `string` | Alert message | +> | notifiedStatus | `boolean` | | +> | acknowledgeStatus | `boolean` | | + ##### Sample CURL request ``` - +curl --request POST \ + --url http://localhost:5000/api/v1/alerts/edit/66577ddae5ff3c91437d0887 \ + --header 'Authorization: ' \ + --header 'Content-Type: application/json' \ + --data '{ + "acknowledgeStatus": true +}' ``` ###### Sample Response ```json - +{ + "success": true, + "msg": "Edited alert", + "data": { + "_id": "66577ddae5ff3c91437d0887", + "checkId": "66577a3fd16dcf7c1ce35148", + "monitorId": "6657789ebf6766ee8e2d2edb", + "userId": "6654d1a2634754f789e1f115", + "status": false, + "message": "This is a test alert", + "notifiedStatus": false, + "acknowledgeStatus": true, + "createdAt": "2024-05-29T19:11:22.205Z", + "updatedAt": "2024-05-29T19:12:23.951Z", + "__v": 0 + } +} ``` @@ -964,22 +1072,38 @@ curl --request POST \ ###### Response Payload -> | Type | Notes | -> | ---- | ------------------- | -> | None | No payload returned | - -###### Body +> | Type | Notes | +> | ------- | --------------------------- | +> | `Alert` | Returns the deleted `Alert` | ##### Sample CURL request ``` - +curl --request POST \ + --url http://localhost:5000/api/v1/alerts/delete/66577ddae5ff3c91437d0887 \ + --header 'Authorization: ' \ ``` ###### Sample Response ```json - +{ + "success": true, + "msg": "Deleted alert", + "data": { + "_id": "66577ddae5ff3c91437d0887", + "checkId": "66577a3fd16dcf7c1ce35148", + "monitorId": "6657789ebf6766ee8e2d2edb", + "userId": "6654d1a2634754f789e1f115", + "status": false, + "message": "This is a test alert", + "notifiedStatus": false, + "acknowledgeStatus": true, + "createdAt": "2024-05-29T19:11:22.205Z", + "updatedAt": "2024-05-29T19:12:23.951Z", + "__v": 0 + } +} ``` From 43e3fc19d3679b41164094b352fee1179b9a0edc Mon Sep 17 00:00:00 2001 From: M M Date: Wed, 29 May 2024 23:50:22 -0700 Subject: [PATCH 6/9] Navbar now takes up the full viewport width. --- Client/src/Components/NavBar/index.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/src/Components/NavBar/index.jsx b/Client/src/Components/NavBar/index.jsx index fa1a8bc15..0caf90ff5 100644 --- a/Client/src/Components/NavBar/index.jsx +++ b/Client/src/Components/NavBar/index.jsx @@ -46,8 +46,8 @@ function NavBar() { }; return ( - - + + Date: Thu, 30 May 2024 15:14:26 -0700 Subject: [PATCH 7/9] Adjusted the class of maxWidth from xl to xxl for better responsiveness. --- Client/src/Components/NavBar/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/src/Components/NavBar/index.jsx b/Client/src/Components/NavBar/index.jsx index 0caf90ff5..2c255eae0 100644 --- a/Client/src/Components/NavBar/index.jsx +++ b/Client/src/Components/NavBar/index.jsx @@ -47,7 +47,7 @@ function NavBar() { return ( - + Date: Sat, 1 Jun 2024 14:29:54 -0700 Subject: [PATCH 8/9] Implemented the sidebar component and added it to the home layout screen. --- Client/src/Components/DashboardMenu/index.css | 33 +++++++++++-------- .../src/Components/DashboardSidebar/index.css | 13 ++++++++ .../src/Components/DashboardSidebar/index.jsx | 19 +++++++++++ Client/src/Layouts/HomeLayout/index.css | 12 ++++++- Client/src/Layouts/HomeLayout/index.jsx | 30 ++++++++--------- 5 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 Client/src/Components/DashboardSidebar/index.css create mode 100644 Client/src/Components/DashboardSidebar/index.jsx diff --git a/Client/src/Components/DashboardMenu/index.css b/Client/src/Components/DashboardMenu/index.css index 37c84655b..3c58afdb7 100644 --- a/Client/src/Components/DashboardMenu/index.css +++ b/Client/src/Components/DashboardMenu/index.css @@ -1,15 +1,20 @@ +.dashboard-menu-container { + display: flex; + flex-direction: column; + padding: 20px; +} + .icon-container { - display: flex; - align-items: center; - margin-bottom: 12px; - } - - .text-container { - display: flex; - align-items: center; - } - - .dashboard-menu-text { - margin-left: 8px; - } - \ No newline at end of file + display: flex; + align-items: center; + margin-bottom: 12px; +} + +.text-container { + display: flex; + align-items: center; +} + +.dashboard-menu-text { + margin-left: 8px; +} diff --git a/Client/src/Components/DashboardSidebar/index.css b/Client/src/Components/DashboardSidebar/index.css new file mode 100644 index 000000000..83b0b349b --- /dev/null +++ b/Client/src/Components/DashboardSidebar/index.css @@ -0,0 +1,13 @@ +.dashboard-sidebar { + height: 100vh; + width: 250px; + background-color: #f4f4f4; + box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1); + position: fixed; + top: 0; + left: 0; + display: flex; + flex-direction: column; + padding-top: 60px; + } + \ No newline at end of file diff --git a/Client/src/Components/DashboardSidebar/index.jsx b/Client/src/Components/DashboardSidebar/index.jsx new file mode 100644 index 000000000..d506256a3 --- /dev/null +++ b/Client/src/Components/DashboardSidebar/index.jsx @@ -0,0 +1,19 @@ +import DashboardMenu from '../../Components/DashboardMenu'; +import './index.css'; + +/** + * @component + * DashboardSidebar component serves as a sidebar containing the DashboardMenu. + * + * @returns {JSX.Element} The JSX element representing the DashboardSidebar component. + */ + +function DashboardSidebar() { + return ( +
+ +
+ ); +} + +export default DashboardSidebar; diff --git a/Client/src/Layouts/HomeLayout/index.css b/Client/src/Layouts/HomeLayout/index.css index d6a7f5707..3adc8ef22 100644 --- a/Client/src/Layouts/HomeLayout/index.css +++ b/Client/src/Layouts/HomeLayout/index.css @@ -1 +1,11 @@ -/*Homelayout styles*/ \ No newline at end of file +.home-layout { + display: flex; + } + + .main-content { + margin-left: 250px; + flex: 1; + padding: 20px; + overflow-y: auto; + } + \ No newline at end of file diff --git a/Client/src/Layouts/HomeLayout/index.jsx b/Client/src/Layouts/HomeLayout/index.jsx index ed1d06fe6..7f0615907 100644 --- a/Client/src/Layouts/HomeLayout/index.jsx +++ b/Client/src/Layouts/HomeLayout/index.jsx @@ -1,21 +1,17 @@ -import NavBar from '../../Components/NavBar' -import { Outlet } from 'react-router' -import Home from '../../Pages/Home' -import './index.css' -import ChartsOverviewDemo from '../../Components/DashboardProgressBars' -import DashboardSettings from '../../Components/DashboardSettingsIcon' - +import NavBar from '../../Components/NavBar'; +import { Outlet } from 'react-router'; +import DashboardSidebar from '../../Components/DashboardSidebar'; +import './index.css'; const HomeLayout = () => { - return ( - <> - - - - - - - ) + return ( +
+ +
+ +
+
+ ); } -export default HomeLayout \ No newline at end of file +export default HomeLayout; From fc65ce17ae47946255a8c5a52634b6840d15a1b6 Mon Sep 17 00:00:00 2001 From: M M Date: Sat, 1 Jun 2024 14:54:29 -0700 Subject: [PATCH 9/9] Added the support icon at the bottom of the sidebar. --- .../src/Components/DashboardSidebar/index.css | 22 +++++++++++++++++-- .../src/Components/DashboardSidebar/index.jsx | 12 ++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Client/src/Components/DashboardSidebar/index.css b/Client/src/Components/DashboardSidebar/index.css index 83b0b349b..43af36fbd 100644 --- a/Client/src/Components/DashboardSidebar/index.css +++ b/Client/src/Components/DashboardSidebar/index.css @@ -1,13 +1,31 @@ .dashboard-sidebar { height: 100vh; width: 250px; - background-color: #f4f4f4; + background-color: #f4f4f4; box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1); position: fixed; top: 0; left: 0; display: flex; flex-direction: column; - padding-top: 60px; + justify-content: space-between; + padding: 20px 0; + } + + .menu-container { + margin-top: 60px; + } + + .support-container { + display: flex; + align-items: center; + padding: 10px 20px; + margin-bottom: 40px; + } + + .support-text { + margin-left: 8px; + font-size: 16px; + color: #333; } \ No newline at end of file diff --git a/Client/src/Components/DashboardSidebar/index.jsx b/Client/src/Components/DashboardSidebar/index.jsx index d506256a3..846452dbc 100644 --- a/Client/src/Components/DashboardSidebar/index.jsx +++ b/Client/src/Components/DashboardSidebar/index.jsx @@ -1,9 +1,11 @@ import DashboardMenu from '../../Components/DashboardMenu'; +import SupportIcon from '@mui/icons-material/Support'; +import SvgIcon from '@mui/material/SvgIcon'; import './index.css'; /** * @component - * DashboardSidebar component serves as a sidebar containing the DashboardMenu. + * DashboardSidebar component serves as a sidebar containing the DashboardMenu and a Support icon at the bottom. * * @returns {JSX.Element} The JSX element representing the DashboardSidebar component. */ @@ -11,7 +13,13 @@ import './index.css'; function DashboardSidebar() { return (
- +
+ +
+
+ + Support +
); }