diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 3e3c78534..f33ddcf10 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -205,12 +205,14 @@ const createMonitor = async (req, res, next) => { const monitor = await req.db.createMonitor(req, res); if (notifications && notifications.length !== 0) { - await Promise.all( + const setNotifications = await Promise.all( notifications.map(async (notification) => { notification.monitorId = monitor._id; await req.db.createNotification(notification); }) ); + monitor.notifications = setNotifications; + await monitor.save(); } // Add monitor to job queue req.jobQueue.addJob(monitor._id, monitor); diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 6470215f3..eebb8f496 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -346,12 +346,7 @@ const getMonitorsByTeamId = async (req, res) => { if (normalize !== undefined) { checks = NormalizeData(checks, 10, 100); } - - // Get notifications - const notifications = await Notification.find({ - monitorId: monitor._id, - }); - return { ...monitor.toObject(), checks, notifications }; + return { ...monitor.toObject(), checks }; }) ); return monitorsWithChecks;