From 78170856f052cbfb5242d2ad59fe48b2c383d469 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 24 Oct 2024 11:56:27 +0800 Subject: [PATCH] Refactor createMonitor to remove redundany check --- Server/controllers/monitorController.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index eaed33c81..582625e32 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -225,15 +225,15 @@ const createMonitor = async (req, res, next) => { const notifications = req.body.notifications; const monitor = await req.db.createMonitor(req, res); - if (notifications && notifications.length !== 0) { - monitor.notifications = await Promise.all( + monitor.notifications = + notifications && + (await Promise.all( notifications.map(async (notification) => { notification.monitorId = monitor._id; await req.db.createNotification(notification); }) - ); - await monitor.save(); - } + )); + await monitor.save(); // Add monitor to job queue req.jobQueue.addJob(monitor._id, monitor); return res.status(201).json({