Skip to content

Instantly share code, notes, and snippets.

@sizovilya
Last active July 20, 2016 11:24
Show Gist options
  • Save sizovilya/8aa2e504b78bacdf96e58e9c14a38765 to your computer and use it in GitHub Desktop.
Save sizovilya/8aa2e504b78bacdf96e58e9c14a38765 to your computer and use it in GitHub Desktop.
Server filter
'getPostsSearch': function (gameId, minAge, maxAge, micro, count, title, additional, platformId, countryId) {
var filter = {};
if(gameId)
filter['game.id'] = gameId;
if(minAge || maxAge) {
if (minAge != '' && maxAge != '') {
filter['$or'] = [{minAge: {$gte: minAge * 1, $lte: maxAge * 1}}, {
maxAge: {
$gte: minAge * 1,
$lte: maxAge * 1
}
}, {$and: [{minAge: {$lt: minAge * 1}}, {maxAge: {$gt: maxAge * 1}}]}];
}
else {
if (minAge != '') {
filter['minAge'] = {$gte: minAge * 1};
}
if (maxAge != '') {
filter['maxAge'] = {$lte: maxAge * 1};
}
}
}
if(micro)
filter['mic'] = micro;
if (additional) {
if (title === 'Counter-Strike: Global Offensive')
{
if (additional.minRank) {
filter['additional.minRank.value'] = { $gte: additional.minRank * 1 };
}
if (additional.maxRank) {
filter['additional.maxRank.value'] = { $lte: additional.maxRank * 1 };
}
if (additional.csmode) {
filter['additional.mode.value'] = additional.csmode;
}
}
if (title === 'Pokemon Go')
{
if(additional.location)
{
filter['additional.location.text'] = additional.location;
}
}
}
if (platformId)
filter['platform.id'] = platformId;
if (countryId)
filter['country.id'] = countryId;
return Posts.find(filter,{limit:count}).fetch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment