orderByWins has limit parameter to slice response

Limit the number of rows returned, used for frontpage where we display
max 20.
This commit is contained in:
2021-02-17 19:21:33 +01:00
parent 38eb98e68b
commit bca4558d59

View File

@@ -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,