From 6b29a56da138b4b905e553dec6922251c1867edb Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 19 Jul 2024 20:27:38 -0700 Subject: [PATCH] Changed sort order of checks to always be newest->oldest. Updated check search accordingly --- Server/db/MongoDB.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Server/db/MongoDB.js b/Server/db/MongoDB.js index c0b0948a2..8f498258d 100644 --- a/Server/db/MongoDB.js +++ b/Server/db/MongoDB.js @@ -274,7 +274,7 @@ const getMonitorById = async (req, res) => { try { const monitor = await Monitor.findById(req.params.monitorId); const checks = await Check.find({ monitorId: monitor._id }).sort({ - createdAt: -1, + createdAt: 1, }); const monitorWithChecks = { ...monitor.toObject(), checks }; return monitorWithChecks; @@ -299,15 +299,16 @@ const getMonitorsByUserId = async (req, res) => { const monitorsWithChecks = await Promise.all( monitors.map(async (monitor) => { if (limit) { - // Checks are order oldest -> newest + // Checks are order newest -> oldest const checks = await Check.find({ monitorId: monitor._id }) .sort({ - createdAt: 1, + createdAt: -1, }) .limit(limit); return { ...monitor.toObject(), checks }; } else { - // Checks are order oldest -> newest + // Checks are order newest -> oldest + // TODO is this ever used? const checks = await Check.find({ monitorId: monitor._id }).sort({ createdAt: 1, });