0

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.

3
  • 1
    what are you trying to do? you are calling db.Meals.findAll(); and with one givenId and 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? Commented Oct 25, 2017 at 22:35
  • 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'. Commented Oct 25, 2017 at 22:43
  • You are using MongoDB right? Commented Oct 25, 2017 at 22:44

1 Answer 1

1

You have declared your variables as checkReview and checkRating (which are also same as your function names) but you are using averageRating and reviews. You should declare the below variables:

var averageRating,
    reviews;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.