Merge pull request #769 from bluewave-labs/fix/notifications
Notifications added to monitor object
This commit is contained in:
4 files changed
+18
-15
No files matched your search
@@ -52,7 +52,7 @@ const Configure = () => {
|
|||||||
const [monitor, setMonitor] = useState({});
|
const [monitor, setMonitor] = useState({});
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
const { monitorId } = useParams();
|
const { monitorId } = useParams();
|
||||||
|
console.log(monitor);
|
||||||
const idMap = {
|
const idMap = {
|
||||||
"monitor-url": "url",
|
"monitor-url": "url",
|
||||||
"monitor-name": "name",
|
"monitor-name": "name",
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -357,16 +359,13 @@ const pauseMonitor = async (req, res, next) => {
|
|||||||
await req.jobQueue.addJob(monitor._id, monitor);
|
await req.jobQueue.addJob(monitor._id, monitor);
|
||||||
}
|
}
|
||||||
monitor.isActive = !monitor.isActive;
|
monitor.isActive = !monitor.isActive;
|
||||||
const updatedMonitor = await req.db.editMonitor(
|
monitor.save();
|
||||||
req.params.monitorId,
|
|
||||||
monitor
|
|
||||||
);
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: updatedMonitor.isActive
|
msg: monitor.isActive
|
||||||
? successMessages.MONITOR_RESUME
|
? successMessages.MONITOR_RESUME
|
||||||
: successMessages.MONITOR_PAUSE,
|
: successMessages.MONITOR_PAUSE,
|
||||||
data: updatedMonitor,
|
data: monitor,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
|
|||||||
@@ -284,7 +284,9 @@ const getMonitorById = async (monitorId) => {
|
|||||||
const notifications = await Notification.find({
|
const notifications = await Notification.find({
|
||||||
monitorId: monitorId,
|
monitorId: monitorId,
|
||||||
});
|
});
|
||||||
return { ...monitor.toObject(), notifications };
|
monitor.notifications = notifications;
|
||||||
|
const monitorWithNotifications = await monitor.save();
|
||||||
|
return monitorWithNotifications;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -344,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;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const mongoose = require("mongoose");
|
const mongoose = require("mongoose");
|
||||||
|
const Notification = require("./Notification");
|
||||||
|
|
||||||
const MonitorSchema = mongoose.Schema(
|
const MonitorSchema = mongoose.Schema(
|
||||||
{
|
{
|
||||||
@@ -43,6 +44,12 @@ const MonitorSchema = mongoose.Schema(
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: 60000,
|
default: 60000,
|
||||||
},
|
},
|
||||||
|
notifications: [
|
||||||
|
{
|
||||||
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
|
ref: "Notification",
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
|
|||||||
Reference in new issue
Block a user