<commit_before>'use strict';

module.exports = function(express) {

  const router = express.Router();
  const async = require('async');
  const db = require('../server/db.js');

  let meals = require('../models/meals.js');
  let users = require('../models/users.js');

  router.route('/')

  .get((req, res) => {

    async.waterfall([
      (callback) => {
        meals.findAll(
        (err) => {
          res.status(500).json({ error: err });
        },
        (meals) => {
          callback(null, meals);
        });
      }
    ],
    (err, meals) => {
      if(err) {
        res.status(500).json({ error: err });
      }
      res.status(200).json({ meals });
    });
  })

  .delete((req, res) => {
    let data = req.body;

    async.waterfall([
      (callback) => {
        meals.destroy(data,
        (err) => {
          res.status(500).json({ error: err });
        },
        (destroyedMeal) => {
          callback(null, destroyedMeal);
        });
      }
    ],
    (err, destroyedMeal) => {
      if(err) {
        res.status(500).json({ error: err });
      }
      res.status(200).json({ destroyedMeal });
    });
  })

  .put((req, res) => {
    let data = req.body;

    async.waterfall([
      (callback) => {
        users.find(data,
        (err) => {
          res.status(500).json({ error: err });
        },
        (foundUser) => {
          callback(null, foundUser);
        });
      },
      (foundUser, callback) => {
        meals.create(data,
        (err) => {
          res.status(500).json({ error: err });
        },
        (createdMeal) => {
          callback(null, foundUser);
        });
      },
      (foundUser, callback) => {
        meals.find(data,
        (err) => {
          res.status(500).json({ error: err });
        },
        (createdMeal) => {
          callback(null, createdMeal);
        });
      }
    ],
    (err, createdMeal) => {
      if(err) {
        res.status(500).json({ error: err });
      }
      res.status(200).json({ createdMeal });
    });
  });

  router.route('/:userId')

  .get((req, res) => {
    let userId = req.params.userId;
    console.log(res.body.date);

    async.waterfall([
      (callback) => {
        meals.findAll(
        (err) => {
          res.status(500).json({ error: err });
        },
        (allMeals) => {
          let userMeals = [];
          for(let i = 0; i < allMeals.length; i++) {
            if(allMeals[i].userId === userId) {
              userMeals.push(allMeals[i]);
            }
          }
          userMeals.filter((dayFilter) => {
            return dayFilter.date == res.body.date;
          })
          callback(null, dayFilter);
        });
      }
    ],
    (err, dayFilter) => {
      if(err) {
        res.status(500).json({ error: err });
      }
      res.status(200).json({ dayFilter });
    });
  });

  return router;

};<commit_msg>Fixed console<commit_after>'use strict';

module.exports = function(express) {

  const router = express.Router();
  const async = require('async');
  const db = require('../server/db.js');

  let meals = require('../models/meals.js');
  let users = require('../models/users.js');

  router.route('/')

  .get((req, res) => {

    async.waterfall([
      (callback) => {
        meals.findAll(
        (err) => {
          res.status(500).json({ error: err });
        },
        (meals) => {
          callback(null, meals);
        });
      }
    ],
    (err, meals) => {
      if(err) {
        res.status(500).json({ error: err });
      }
      res.status(200).json({ meals });
    });
  })

  .delete((req, res) => {
    let data = req.body;

    async.waterfall([
      (callback) => {
        meals.destroy(data,
        (err) => {
          res.status(500).json({ error: err });
        },
        (destroyedMeal) => {
          callback(null, destroyedMeal);
        });
      }
    ],
    (err, destroyedMeal) => {
      if(err) {
        res.status(500).json({ error: err });
      }
      res.status(200).json({ destroyedMeal });
    });
  })

  .put((req, res) => {
    let data = req.body;

    async.waterfall([
      (callback) => {
        users.find(data,
        (err) => {
          res.status(500).json({ error: err });
        },
        (foundUser) => {
          callback(null, foundUser);
        });
      },
      (foundUser, callback) => {
        meals.create(data,
        (err) => {
          res.status(500).json({ error: err });
        },
        (createdMeal) => {
          callback(null, foundUser);
        });
      },
      (foundUser, callback) => {
        meals.find(data,
        (err) => {
          res.status(500).json({ error: err });
        },
        (createdMeal) => {
          callback(null, createdMeal);
        });
      }
    ],
    (err, createdMeal) => {
      if(err) {
        res.status(500).json({ error: err });
      }
      res.status(200).json({ createdMeal });
    });
  });

  router.route('/:userId')

  .get((req, res) => {
    let userId = req.params.userId;

    async.waterfall([
      (callback) => {
        meals.findAll(
        (err) => {
          res.status(500).json({ error: err });
        },
        (allMeals) => {
          let userMeals = [];
          for(let i = 0; i < allMeals.length; i++) {
            if(allMeals[i].userId === userId) {
              userMeals.push(allMeals[i]);
            }
          }
          callback(null, userMeals);
        });
      }
    ],
    (err, userMeals) => {
      if(err) {
        res.status(500).json({ error: err });
      }
      res.status(200).json({ userMeals });
    });
  });

  return router;

};
{'fraction_non_alphanumeric': 0.1928888888888889, 'fraction_numerical': 0.015288888888888888, 'mean_word_length': 1.5807339449541284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 56, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '297872', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1824, 'n_words': 292}