Created
November 18, 2014 14:19
-
-
Save baudehlo/2f582c4a1db05f5e3a64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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