mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-19 08:09:45 -06:00
Merge pull request #400 from bluewave-labs/fix/sort-order
Fix/sort order, resolves #397
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user