Merge pull request #514 from bluewave-labs/feat/be/add-notifications-to-monitors
Add notifications to monitors before returning
This commit is contained in:
1 file changed
+9
-2
@@ -2,6 +2,7 @@ const Monitor = require("../../../models/Monitor");
|
|||||||
const Check = require("../../../models/Check");
|
const Check = require("../../../models/Check");
|
||||||
const PageSpeedCheck = require("../../../models/PageSpeedCheck");
|
const PageSpeedCheck = require("../../../models/PageSpeedCheck");
|
||||||
const { errorMessages } = require("../../../utils/messages");
|
const { errorMessages } = require("../../../utils/messages");
|
||||||
|
const Notification = require("../../../models/Notification");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all monitors
|
* Get all monitors
|
||||||
@@ -63,7 +64,8 @@ const getMonitorById = async (req, res) => {
|
|||||||
createdAt: sortOrder,
|
createdAt: sortOrder,
|
||||||
})
|
})
|
||||||
.limit(limit);
|
.limit(limit);
|
||||||
const monitorWithChecks = { ...monitor.toObject(), checks };
|
const notifications = await Notification.find({ monitorId: monitor._id });
|
||||||
|
const monitorWithChecks = { ...monitor.toObject(), checks, notifications };
|
||||||
return monitorWithChecks;
|
return monitorWithChecks;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
@@ -119,7 +121,12 @@ const getMonitorsByUserId = async (req, res) => {
|
|||||||
createdAt: sortOrder,
|
createdAt: sortOrder,
|
||||||
})
|
})
|
||||||
.limit(limit);
|
.limit(limit);
|
||||||
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