Hello, in my code i have a form with 3 FormControl of type select. I am tryng to write a generic query that is generated from the value of the 3 selects but i dont know how to write the corect syntax. here is my code until now:
Meteor.publish('rebatesCount', function rebates(brand, amount, quantity) {
//default values for brand, amount and quantity is ' ' -> empty string
check(brand, String);
check(amount, String);
check(quantity, Number);
if (Roles.userIsInRole(this.userId, 'admin')) {
if (brand === '' && amount === '') {
return Rebates.find({ brand: { $exists: true }, amount: { $exists: true }, printed: false });
}
if (brand !== '' && amount === '') {
return Rebates.find(
{ brand, amount: { $exists: true }, printed: false },
{ limit: quantity },
);
}
if (brand === '' && amount !== '') {
return Rebates.find({ amount, printed: false }, { limit: quantity });
}
if (brand !== '' && amount !== '') {
return Rebates.find({ brand, amount, printed: false }, { limit: quantity });
}
}
return null;
});
I know that there must be a better way, the thing i am struggling with is how to say :
give me all rebates with this brand
or all brands and this amount
or this brand and this amount
or this brand, all the amounts, but with this limit … etc.
Thank you.