From bca4558d590c41cde247263b04a604743107c16a Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Wed, 17 Feb 2021 19:21:33 +0100 Subject: [PATCH] orderByWins has limit parameter to slice response Limit the number of rows returned, used for frontpage where we display max 20. --- api/history.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/api/history.js b/api/history.js index 30ed510..6febeb4 100644 --- a/api/history.js +++ b/api/history.js @@ -269,7 +269,7 @@ const groupByColor = (includeWines = false) => { // highscore - byWineOccurences // highscore - byWinCount -const orderByWins = (includeWines = false) => { +const orderByWins = (includeWines = false, limit = undefined) => { let query = [ { $project: { @@ -315,16 +315,15 @@ const orderByWins = (includeWines = false) => { query = includeWinesSubQuery.concat(query); } - return Winner.aggregate(query); + return Winner.aggregate(query).then(winners => { + if (limit == null) { + return winners; + } + + return winners.slice(0, limit); + }); }; -// highscore - deleteWinner : remove for GDPR purpose - -// lottery - deleteWinner : remove for GDPR purpose -// lottery - update : manual lottery -// lottery - add : manual lottery -// lottery - archive - module.exports = { addWinnerWithWine, all,