Refactor createMonitor to remove redundany check
This commit is contained in:
1 parent
f58bac9ccf
commit
78170856f0
1 file changed
+5
-5
@@ -225,15 +225,15 @@ 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) {
|
monitor.notifications =
|
||||||
monitor.notifications = await Promise.all(
|
notifications &&
|
||||||
|
(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);
|
||||||
})
|
})
|
||||||
);
|
));
|
||||||
await monitor.save();
|
await monitor.save();
|
||||||
}
|
|
||||||
// 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({
|
||||||
|
|||||||
Reference in new issue
Block a user