Changed sort order of checks to always be newest->oldest. Updated check search accordingly

This commit is contained in:
Alex Holliday committed 2024-07-19 20:27:38 -07:00
1 parent fdb59866b3
commit 6b29a56da1
1 file changed
+5 -4
+5 -4
View File
@@ -274,7 +274,7 @@ const getMonitorById = async (req, res) => {
try { try {
const monitor = await Monitor.findById(req.params.monitorId); const monitor = await Monitor.findById(req.params.monitorId);
const checks = await Check.find({ monitorId: monitor._id }).sort({ const checks = await Check.find({ monitorId: monitor._id }).sort({
createdAt: -1, createdAt: 1,
}); });
const monitorWithChecks = { ...monitor.toObject(), checks }; const monitorWithChecks = { ...monitor.toObject(), checks };
return monitorWithChecks; return monitorWithChecks;
@@ -299,15 +299,16 @@ const getMonitorsByUserId = async (req, res) => {
const monitorsWithChecks = await Promise.all( const monitorsWithChecks = await Promise.all(
monitors.map(async (monitor) => { monitors.map(async (monitor) => {
if (limit) { if (limit) {
// Checks are order oldest -> newest // Checks are order newest -> oldest
const checks = await Check.find({ monitorId: monitor._id }) const checks = await Check.find({ monitorId: monitor._id })
.sort({ .sort({
createdAt: 1, createdAt: -1,
}) })
.limit(limit); .limit(limit);
return { ...monitor.toObject(), checks }; return { ...monitor.toObject(), checks };
} else { } 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({ const checks = await Check.find({ monitorId: monitor._id }).sort({
createdAt: 1, createdAt: 1,
}); });