From 38eb98e68b5447757e183031cdbb656ab21b6e14 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Wed, 17 Feb 2021 19:20:52 +0100 Subject: [PATCH] Sorting happens in mongo query, no longer in js. --- api/history.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/history.js b/api/history.js index 72680d1..30ed510 100644 --- a/api/history.js +++ b/api/history.js @@ -172,7 +172,8 @@ const latest = () => { }; // lottery - byDate -const groupByDate = (includeWines = false, sort = "desc") => { +const groupByDate = (includeWines = false, sort = "asc") => { + const sortDirection = sort == "asc" ? -1 : 1; const query = [ { $unwind: "$wins" @@ -198,7 +199,7 @@ const groupByDate = (includeWines = false, sort = "desc") => { }, { $sort: { - _id: -1 + date: sortDirection } } ]; @@ -214,7 +215,7 @@ const groupByDate = (includeWines = false, sort = "desc") => { }); } - return Winner.aggregate(query).then(lotteries => (sort != "asc" ? lotteries : lotteries.reverse())); + return Winner.aggregate(query); }; // highscore - byColor