diff --git a/Client/src/Pages/Monitors/Home/index.jsx b/Client/src/Pages/Monitors/Home/index.jsx index c2a532bb9..a03959076 100644 --- a/Client/src/Pages/Monitors/Home/index.jsx +++ b/Client/src/Pages/Monitors/Home/index.jsx @@ -134,7 +134,7 @@ const Monitors = ({ isAdmin }) => { { normalize: null, }); setMonitor(res?.data?.data ?? {}); - setAudits(res?.data?.data?.checks?.[0]?.audits ?? []); + setAudits(res?.data?.data?.checks?.[0]?.audits ?? {}); } catch (error) { logger.error(logger); navigate("/not-found", { replace: true }); diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index e534e0f60..a8b90c084 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -20,6 +20,7 @@ const SERVICE_NAME = "monitorController"; const { errorMessages, successMessages } = require("../utils/messages"); const jwt = require("jsonwebtoken"); const { getTokenFromHeaders } = require("../utils/utils"); +const logger = require("../utils/logger"); /** * Returns all monitors @@ -315,18 +316,21 @@ const deleteMonitor = async (req, res, next) => { try { const monitor = await req.db.deleteMonitor(req, res, next); // Delete associated checks,alerts,and notifications - await req.jobQueue.deleteJob(monitor); - await req.db.deleteChecks(monitor._id); - await req.db.deleteAlertByMonitorId(monitor._id); - await req.db.deletePageSpeedChecksByMonitorId(monitor._id); - await req.db.deleteNotificationsByMonitorId(monitor._id); + try { + await req.jobQueue.deleteJob(monitor); + await req.db.deleteChecks(monitor._id); + await req.db.deletePageSpeedChecksByMonitorId(monitor._id); + await req.db.deleteNotificationsByMonitorId(monitor._id); + } catch (error) { + logger.error( + `Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`, + { + service: SERVICE_NAME, + error: error.message, + } + ); + } - /** - * TODO - * We should remove all checks and alerts associated with this monitor - * when it is deleted so there is no orphaned data - * We also need to make sure to stop all running services for this monitor - */ return res .status(200) .json({ success: true, msg: successMessages.MONITOR_DELETE });