Update getMonitorsByTeamid to use attached notifications
This commit is contained in:
1 parent
5b140198d6
commit
68b50a3059
2 files changed
+4
-7
No files matched your search
@@ -205,12 +205,14 @@ const createMonitor = async (req, res, next) => {
|
|||||||
const monitor = await req.db.createMonitor(req, res);
|
const monitor = await req.db.createMonitor(req, res);
|
||||||
|
|
||||||
if (notifications && notifications.length !== 0) {
|
if (notifications && notifications.length !== 0) {
|
||||||
await Promise.all(
|
const setNotifications = 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);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
monitor.notifications = setNotifications;
|
||||||
|
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);
|
||||||
|
|||||||
@@ -346,12 +346,7 @@ const getMonitorsByTeamId = async (req, res) => {
|
|||||||
if (normalize !== undefined) {
|
if (normalize !== undefined) {
|
||||||
checks = NormalizeData(checks, 10, 100);
|
checks = NormalizeData(checks, 10, 100);
|
||||||
}
|
}
|
||||||
|
return { ...monitor.toObject(), checks };
|
||||||
// Get notifications
|
|
||||||
const notifications = await Notification.find({
|
|
||||||
monitorId: monitor._id,
|
|
||||||
});
|
|
||||||
return { ...monitor.toObject(), checks, notifications };
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return monitorsWithChecks;
|
return monitorsWithChecks;
|
||||||
|
|||||||
Reference in new issue
Block a user