implement level filters

This commit is contained in:
oatmealine 2020-01-25 16:14:08 +03:00
parent 1c56286cd8
commit a9fee71c6a
No known key found for this signature in database
GPG Key ID: C4CB49CFAD721145
1 changed files with 33 additions and 0 deletions

View File

@ -51,6 +51,39 @@ module.exports = (app, db) : void => {
})
.toArray();
switch (Number(req.body.type)) {
case 1: // most downloaded
levels.sort((a, b) => b.downloads - a.downloads);
break;
case 2: // most liked
levels.sort((a, b) => b.likes - a.likes);
break;
case 3: // trending
levels.filter(l => {
l.timestamp || 0 > Date.now() - 604800000;
});
levels.sort((a, b) => b.downloads - a.downloads);
break;
case 4: // recent
levels.sort((a, b) => b.timestamp || 0 - a.timestamp || 0);
break;
case 7: // ~ M a G i C ~
levels.filter(l => {
l.objects || 0 > 1000;
});
levels.sort((a, b) => b.timestamp || 0 - a.timestamp || 0);
break;
case 11: // awarded
levels.filter(l => {
l.stars > 0;
});
levels.sort((a, b) => b.timestamp || 0 - a.timestamp || 0);
break;
case 12: // TODO: followed
case 13: // TODO: friends
levels.filter(() => false);
}
let offset = Math.max(Number(req.body.page) * 10 - 1, 0);
const foundLevels = levels