From 2a79264a9a2debf776fae03b47d69d858e8a0fed Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 31 Jul 2024 13:11:20 -0700 Subject: [PATCH] Added safety check for accessing notifications before inserting --- Server/controllers/monitorController.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 2c68d5660..b6317fa35 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -134,13 +134,14 @@ const createMonitor = async (req, res, next) => { const notifications = req.body.notifications; const monitor = await req.db.createMonitor(req, res); - await Promise.all( - notifications.map(async (notification) => { - notification.monitorId = monitor._id; - await req.db.createNotification(notification); - }) - ); - + if (notifications && notifications.length !== 0) { + await Promise.all( + notifications.map(async (notification) => { + notification.monitorId = monitor._id; + await req.db.createNotification(notification); + }) + ); + } // Add monitor to job queue req.jobQueue.addJob(monitor._id, monitor); return res.status(201).json({