provide default empty notification array
This commit is contained in:
1 parent
4bc9f59d80
commit
83e1cb0304
1 file changed
+5
-7
@@ -538,18 +538,16 @@ class MonitorController {
|
|||||||
const monitorBeforeEdit = await this.db.getMonitorById(monitorId);
|
const monitorBeforeEdit = await this.db.getMonitorById(monitorId);
|
||||||
|
|
||||||
// Get notifications from the request body
|
// Get notifications from the request body
|
||||||
const notifications = req.body.notifications;
|
const notifications = req.body.notifications ?? [];
|
||||||
|
|
||||||
const editedMonitor = await this.db.editMonitor(monitorId, req.body);
|
const editedMonitor = await this.db.editMonitor(monitorId, req.body);
|
||||||
|
|
||||||
await this.db.deleteNotificationsByMonitorId(editedMonitor._id);
|
await this.db.deleteNotificationsByMonitorId(editedMonitor._id);
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
notifications &&
|
notifications.map(async (notification) => {
|
||||||
notifications.map(async (notification) => {
|
notification.monitorId = editedMonitor._id;
|
||||||
notification.monitorId = editedMonitor._id;
|
await this.db.createNotification(notification);
|
||||||
await this.db.createNotification(notification);
|
})
|
||||||
})
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Delete the old job(editedMonitor has the same ID as the old monitor)
|
// Delete the old job(editedMonitor has the same ID as the old monitor)
|
||||||
|
|||||||
Reference in new issue
Block a user