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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user