コード例 #1
0
Meteor.publish('getCurrentWeekMealPlan', function () {
  if (this.userId) {
    var user = this.userId;
    var week = moment().weeks();
    var year = moment().weekYear();
    var mealPlan = Plans.findOne({user: user, week: week, year: year});
    if (mealPlan) {
      var recipeIds = [];
      _.each(mealPlan.meals, function(meal) {
        recipeIds.push(_.values(meal));
      })
      var uniqueIds = _.uniq(_.flatten(recipeIds));
      return Recipes.find({_id: {$in: uniqueIds}});
    }
    else {
      return;
    }
  }
});
コード例 #2
0
 sendWeeklyEmail: function (recipientId, recipientEmail, week, year) {
   check(recipientId, String);
   check(recipientEmail, String);
   check(week, Number);
   check(year, Number);
   console.log('Preparing weekly email...');
   var mealPlan = Plans.findOne({user: recipientId, week: week, year: year});
   if (mealPlan) {
     console.log('Plan found, sending email...')
   var weeksRecipes = mealPlan.meals;
   var recipeIds = [];
   _.each(weeksRecipes, function (recipe) {
     if (recipe.full) {
       recipeIds.push(recipe.full);
     }
     if (recipe.main) {
       recipeIds.push(recipe.main);
     }
     if (recipe.side) {
       recipeIds.push(recipe.side);
     }
   })
   var ingredientList = Meteor.call('buildShoppingList', recipeIds);
   console.log('Building ingrdient list...');
   var recipeData = Recipes.find({_id: {$in: recipeIds}}).fetch();
   console.log('Building recipe list...');
   var shoppingContent = formatShoppingList(ingredientList);
   var recipeContent = formatRecipes(weeksRecipes, recipeData);
   var date = moment().startOf('week').format('MMMM Do')+' - '+moment().endOf('week').format('MMMM Do');
   console.log('Sending email to '+recipientEmail+'...');
   Email.send({
     to: recipientEmail,
     from: 'Eat This <info@eatthis.io>',
     subject: 'Your Menu for '+ date + new Date(),
     html: '<p>'+recipeContent+'</p>'+shoppingContent
   });
 }
 else {
   console.log('No plan found. Not sending email to '+ recipientEmail);
 }
 },
コード例 #3
0
 Meteor.users.find().map(function(user) {
   var week = moment().weeks();
   var year = moment().weekYear();
   var mealPlan = Plans.findOne({user: user._id, week: week, year: year});
   Meteor.call('sendWeeklyEmail', user._id, user.services.facebook.email, week, year);
 });