From fa5eef14c332212e873342a28aff8fbcb62ae7a4 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sat, 26 Oct 2024 18:45:51 +0800 Subject: [PATCH] Revert moving notification check to validation, FE always sends an empty notification array --- Server/controllers/monitorController.js | 11 ++++++----- Server/validation/joi.js | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 9bdce12ef..06dcb9998 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -225,14 +225,15 @@ const createMonitor = async (req, res, next) => { const notifications = req.body.notifications; const monitor = await req.db.createMonitor(req, res); - monitor.notifications = - notifications && - (await Promise.all( + if (notifications && notifications.length > 0) { + monitor.notifications = await Promise.all( notifications.map(async (notification) => { notification.monitorId = monitor._id; - await req.db.createNotification(notification); + return await req.db.createNotification(notification); }) - )); + ); + } + await monitor.save(); // Add monitor to job queue req.jobQueue.addJob(monitor._id, monitor); diff --git a/Server/validation/joi.js b/Server/validation/joi.js index 48edc6f9f..fece02926 100644 --- a/Server/validation/joi.js +++ b/Server/validation/joi.js @@ -227,7 +227,7 @@ const createMonitorBodyValidation = joi.object({ usage_memory: joi.number(), usage_disk: joi.number(), }), - notifications: joi.array().items(joi.object()).min(1), + notifications: joi.array().items(joi.object()), }); const editMonitorBodyValidation = joi.object({