Added safety check for accessing notifications before inserting

This commit is contained in:
Alex Holliday
2024-07-31 13:11:20 -07:00
parent 7d3bc7ee8a
commit 2a79264a9a
+8 -7
View File
@@ -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({