Fixed non functioning code

This commit is contained in:
Alex Holliday committed 2024-07-12 10:24:46 -07:00
1 parent 7462458eca
commit 12e85aed03
3 files changed
+16 -13

No files matched your search

+7 -7
View File
@@ -293,19 +293,19 @@ const getMonitorById = async (req, res) => {
*/
const getMonitorsByUserId = async (req, res) => {
try {
const limit = req.body.limit;
const limit = req.query.limit;
const monitors = await Monitor.find({ userId: req.params.userId });
// Map each monitor to include its associated checks
const monitorsWithChecks = await Promise.all(
monitors.map(async (monitor) => {
if(limit) {
if (limit) {
// Checks are order oldest -> newest
const checks = await Check.find({ monitorId: monitor._id }).sort({
createdAt: 1,
}).limit(limit);;
const checks = await Check.find({ monitorId: monitor._id })
.sort({
createdAt: 1,
})
.limit(limit);
return { ...monitor.toObject(), checks };
} else {
// Checks are order oldest -> newest
const checks = await Check.find({ monitorId: monitor._id }).sort({