Added safety check for accessing notifications before inserting

This commit is contained in:
Alex Holliday committed 2024-07-31 13:11:20 -07:00
1 parent 7d3bc7ee8a
commit 2a79264a9a
1 file changed
+2 -1
+2 -1
View File
@@ -134,13 +134,14 @@ const createMonitor = async (req, res, next) => {
const notifications = req.body.notifications; const notifications = req.body.notifications;
const monitor = await req.db.createMonitor(req, res); const monitor = await req.db.createMonitor(req, res);
if (notifications && notifications.length !== 0) {
await Promise.all( await Promise.all(
notifications.map(async (notification) => { notifications.map(async (notification) => {
notification.monitorId = monitor._id; notification.monitorId = monitor._id;
await req.db.createNotification(notification); await req.db.createNotification(notification);
}) })
); );
}
// Add monitor to job queue // Add monitor to job queue
req.jobQueue.addJob(monitor._id, monitor); req.jobQueue.addJob(monitor._id, monitor);
return res.status(201).json({ return res.status(201).json({