From 1664bc09eaa9e99b6c5a889a348bdccf05505f6b Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 30 Jul 2024 13:25:56 -0700 Subject: [PATCH] Add delete method --- Server/db/mongo/MongoDB.js | 6 ++---- Server/db/mongo/modules/notificationModule.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Server/db/mongo/MongoDB.js b/Server/db/mongo/MongoDB.js index c03e2db1a..2813a3c00 100644 --- a/Server/db/mongo/MongoDB.js +++ b/Server/db/mongo/MongoDB.js @@ -65,8 +65,6 @@ const { getAllMonitors, getMonitorById, getMonitorsByUserId, - getMonitorByIdForIncidents, - getMonitorsByUserIdForIncidents, createMonitor, deleteMonitor, deleteAllMonitors, @@ -123,6 +121,7 @@ const { const { createNotification, getNotificationsByMonitorId, + deleteNotificationsByMonitorId, } = require("./modules/notificationModule"); module.exports = { @@ -141,8 +140,6 @@ module.exports = { getAllMonitors, getMonitorById, getMonitorsByUserId, - getMonitorByIdForIncidents, - getMonitorsByUserIdForIncidents, createMonitor, deleteMonitor, deleteAllMonitors, @@ -169,4 +166,5 @@ module.exports = { deleteMaintenanceWindowByUserId, createNotification, getNotificationsByMonitorId, + deleteNotificationsByMonitorId, }; diff --git a/Server/db/mongo/modules/notificationModule.js b/Server/db/mongo/modules/notificationModule.js index 7ed2d2064..f5c8708f4 100644 --- a/Server/db/mongo/modules/notificationModule.js +++ b/Server/db/mongo/modules/notificationModule.js @@ -1,5 +1,4 @@ const Notification = require("../../../models/Notification"); -const Notification = require("../../../models/Notification"); /** * Creates a new notification. @@ -35,7 +34,17 @@ const getNotificationsByMonitorId = async (monitorId) => { } }; +const deleteNotificationsByMonitorId = async (monitorId) => { + try { + const result = await Notification.deleteMany({ monitorId }); + return result.deletedCount; + } catch (error) { + throw error; + } +}; + module.exports = { createNotification, getNotificationsByMonitorId, + deleteNotificationsByMonitorId, };