diff --git a/Client/src/Pages/Monitors/Configure/index.jsx b/Client/src/Pages/Monitors/Configure/index.jsx index 61d7d155c..8d2b822eb 100644 --- a/Client/src/Pages/Monitors/Configure/index.jsx +++ b/Client/src/Pages/Monitors/Configure/index.jsx @@ -52,7 +52,7 @@ const Configure = () => { const [monitor, setMonitor] = useState({}); const [errors, setErrors] = useState({}); const { monitorId } = useParams(); - + console.log(monitor); const idMap = { "monitor-url": "url", "monitor-name": "name", @@ -144,6 +144,7 @@ const Configure = () => { if (pauseUptimeMonitor.fulfilled.match(action)) { const monitor = action.payload.data; setMonitor(monitor); + console.log(monitor.notifications); } else if (pauseUptimeMonitor.rejected.match(action)) { throw new Error(action.error.message); } diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index e7147b1cc..3e3c78534 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -357,16 +357,13 @@ const pauseMonitor = async (req, res, next) => { await req.jobQueue.addJob(monitor._id, monitor); } monitor.isActive = !monitor.isActive; - const updatedMonitor = await req.db.editMonitor( - req.params.monitorId, - monitor - ); + monitor.save(); return res.status(200).json({ success: true, - msg: updatedMonitor.isActive + msg: monitor.isActive ? successMessages.MONITOR_RESUME : successMessages.MONITOR_PAUSE, - data: updatedMonitor, + data: monitor, }); } catch (error) { error.service = SERVICE_NAME; diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index e2e93bcfb..6470215f3 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -284,7 +284,9 @@ const getMonitorById = async (monitorId) => { const notifications = await Notification.find({ monitorId: monitorId, }); - return { ...monitor.toObject(), notifications }; + monitor.notifications = notifications; + const monitorWithNotifications = await monitor.save(); + return monitorWithNotifications; } catch (error) { throw error; } diff --git a/Server/models/Monitor.js b/Server/models/Monitor.js index 525f4e4eb..ee4eb890d 100644 --- a/Server/models/Monitor.js +++ b/Server/models/Monitor.js @@ -1,4 +1,5 @@ const mongoose = require("mongoose"); +const Notification = require("./Notification"); const MonitorSchema = mongoose.Schema( { @@ -43,6 +44,12 @@ const MonitorSchema = mongoose.Schema( type: Number, default: 60000, }, + notifications: [ + { + type: mongoose.Schema.Types.ObjectId, + ref: "Notification", + }, + ], }, { timestamps: true,