<commit_before>var http = require('http');
var MealPlan = require('./mealPlanModel');

var saveMealPlan = function(recipes){
  var recipeIds = [];
  for (var i = 0; i < recipes.length; i++) {
    recipeIds.push(recipes[i].id);
  }

  new MealPlan({
    'userId': 0
  }).save().then(function(mealPlan){
    return mealPlan.recipes().attach(recipeIds);
  }).catch(function(error) {
    console.error("On associating recipes with meal plan got error:", error);
  });
};


module.exports = {
  createMealPlan: function (request, response) {
    saveMealPlan(request.body.recipes);
    response.status(200).send({});
  },
};<commit_msg>Meal plans now saved with userId<commit_after>var http = require('http');
var MealPlan = require('./mealPlanModel');

var saveMealPlan = function(requestBody){
  var recipeIds = [];
  for (var i = 0; i < requestBody.recipes.length; i++) {
    recipeIds.push(requestBody.recipes[i].id);
  }

  var userId = requestBody.userId || 0;
  new MealPlan({
    'userId': userId
  }).save().then(function(mealPlan){
    return mealPlan.recipes().attach(recipeIds);
  }).catch(function(error) {
    console.error("On associating recipes with meal plan got error:", error);
  });
};


module.exports = {
  createMealPlan: function (request, response) {
    saveMealPlan(request.body);
    response.status(200).send({});
  },
};
{'fraction_non_alphanumeric': 0.16939078751857356, 'fraction_numerical': 0.007429420505200594, 'mean_word_length': 4.22093023255814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7134263', 'n_tokens_mistral': 451, 'n_tokens_neox': 442, 'n_words': 95}