Change order url to invitee ID, add invitee model

This commit is contained in:
Ben Ramey
2014-05-13 13:11:43 -05:00
parent e4552ebfe4
commit d02bd6c659
10 changed files with 136 additions and 72 deletions

View File

@@ -1,33 +1,36 @@
// EmailService.js
var sendgrid = require("sendgrid");
exports.sendRunEmails = function(runData) {
var emailText = "You've been invited to " + runData.creatorName + "'s lunch run: '"
+ runData.name + "'! \n\n Put in your order here:\nhttp://www.lunchrun.me/#/run/"
+ runData.id + "/order/";
var options = {
fromname: runData.creatorName + " via LunchRun.me",
from: sails.config.email.fromAddress,
subject: "You've been invited to a lunch run!",
replyto: runData.creatorEmail
};
var sg = sendgrid(sails.config.email.apiUser, sails.config.email.apiKey);
exports.sendOrderEmail = function(inviteeData) {
Run.findOne({ id: inviteeData.run_id }, function(err, runData) {
if (err) {
console.log(err);
return;
}
for (var idx in runData.invitees) {
var invitee = runData.invitees[idx];
var specificOptions = options;
specificOptions.to = invitee.email;
specificOptions.toname = invitee.name;
specificOptions.text = emailText + invitee.name;
var emailText = "You've been invited to " + runData.creatorName + "'s lunch run: '"
+ runData.name + "'! \n\n Put in your order here:\nhttp://www.lunchrun.me/#/order/"
+ inviteeData.id;
var options = {
fromname: runData.creatorName + " via LunchRun.me",
from: sails.config.email.fromAddress,
to: inviteeData.email,
toname: inviteeData.name,
subject: "You've been invited to a lunch run!",
replyto: runData.creatorEmail,
text: emailText
};
var sg = sendgrid(sails.config.email.apiUser, sails.config.email.apiKey);
console.log(specificOptions);
sg.send(options, function(err, response) {
if (err) {
console.log(err);
} else {
console.log("message sent from: " + runData.creatorEmail + ", to: " + inviteeData.email);
}
});
sg.send(specificOptions, function(err, response) {
if (err) {
console.log(err);
} else {
console.log("message sent from: " + runData.creatorEmail);
}
});
}
console.log(options);
});
};