From 4601f956866a6c715b2b172b102bc28a78666874 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 5 Nov 2024 12:27:13 +0800 Subject: [PATCH] refactor getMonitorById for clarity --- Server/db/mongo/modules/monitorModule.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index c40e7ea7b..76761ef26 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -314,12 +314,12 @@ const getMonitorById = async (monitorId) => { const notifications = await Notification.find({ monitorId: monitorId, }); - const updatedMonitor = await Monitor.findByIdAndUpdate( - monitorId, - { notifications }, - { new: true } - ).populate("notifications"); - return updatedMonitor; + + // Update monitor with notifications and save + monitor.notifications = notifications; + await monitor.save(); + + return monitor; } catch (error) { error.service = SERVICE_NAME; error.method = "getMonitorById";