Last active
December 20, 2015 15:19
-
-
Save ericf/6153024 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env node | |
var async = require('async'), | |
email = require('../lib/email'), | |
invs = require('../lib/invitations'); | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
process.stdout.write('Are you sure you want to BLAST OFF EMAILS? (yes/NO): '); | |
process.stdin.once('data', function (answer) { | |
answer = answer.toString().trim().toLowerCase(); | |
if (answer === 'yes') { | |
sendRsvpEmails(); | |
} else { | |
console.log('Aborting!'); | |
process.exit(); | |
} | |
}); | |
function sendRsvpEmails() { | |
console.log('Loading invitations from database...'); | |
invs.loadInvitations(function (err, invitations) { | |
if (err) { throw err; } | |
async.eachSeries(invitations, sendEmail, function (err) { | |
console.log('Done!'); | |
process.exit(); | |
}); | |
}); | |
} | |
function sendEmail(invitation, callback) { | |
email.sendRsvpLink(invitation.id, function (err, res, body) { | |
if (err) { | |
console.log(err); | |
} else { | |
console.log('Sent RSVP link to Invitation: ' + invitation.id + ' recipients.'); | |
} | |
callback(null); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment