Skip to content

Instantly share code, notes, and snippets.

@baudehlo
Created November 18, 2014 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baudehlo/2f582c4a1db05f5e3a64 to your computer and use it in GitHub Desktop.
Save baudehlo/2f582c4a1db05f5e3a64 to your computer and use it in GitHub Desktop.
function _sendInvitationReminder(callback) {
async.waterfall([
// 1. Get all invites to be reminded of.
function(callback) {
getExternalInvitations(callback);
},
// 2. Send out the reminders.
function(invitations, callback) {
logger.debug('invites: ' + invitations);
async.each(invitations, function(invite, inner_callback) {
// get the user token
var email = invite.email;
var emailEscaped = email.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
var conditions = {
email: { $regex: new RegExp('^' + emailEscaped + '$', "i") }
};
app.db.models.UserToken.findOne(conditions, function(err, tokenObj) {
if (err) return inner_callback(err);
invite.signupToken = tokenObj.token; // insert token!
logger.debug("Token is: " + invite.signupToken);
var daakiyaTemplate = 'cf-v5-problem-invitation';
// create payload
var payload = createInvitePayload(app, invite);
// Invite via daakiya.
logger.debug("Sending reminder to: " + email.toLowerCase());
daakiya(app).sendMail(payload, daakiyaTemplate); // make the http call to send out the invite.
inner_callback();
});
}, callback);
}
], // 3. Finally...
function (err, result) {
if (err) {
logger.error("Error: " + err);
callback(err);
} else {
logger.info('Result is: ' + result);
callback(result);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment