I'm currently pulling the below response outputs; I am trying to create 2 simple filters, so that only 'healthyMeals' that pass these 2 filters, will display, or output.
Current working output (before 2 filter):
{
"healthyMeals" : [
{
"id": 310,
"avRating": 2.2,
"name": "Peanut butter soup",
"expireDate": "12-02-2017",
"difficulty": "easy",
"reviews": 999
},
Attempt (trying to add 2 filters).
this.getHealthy = function(res, req) {
var checkReview;
var checkRating;
function checkRating() {
if (averageRating > 4.1){
res.res.json({
"message" : "pass",
});
}
else {
res.res.json({
"message" : "Could not find meal",
});
}
};
function checkReview() {
if (reviews >= 5){
res.res.json({
"message" : "pass",
});
}
else {
res.res.json({
"message" : "Could not find meal",
});
}
};
db.Meals.findAll({
where: {
id : givenId,
// averageRating : checkRating(),
// reviews : checkReview()
}
})
The above two properties with comments, breaks app and doesn't work when uncommented out.
How could I loop through all healthyMeals property values of 'averageRating' and 'reviews' and if they pass the 2 filter tests, then, and only then display? If not message 'Not found' displays.
db.Meals.findAll();and with onegivenIdand two filter functions, but those filter functions responds a json which doesn't really make sense? shouldnt they return values for your to use in your findAll query?healthyMealsproperty values of 'averageRating' and 'reviews' and if they pass the 2 filter tests, then, and only then display? If not message 'not found'.