Skip to content

Instantly share code, notes, and snippets.

@lowe0292
Created January 29, 2015 15:23
Show Gist options
  • Save lowe0292/fa3737fdabdff4059629 to your computer and use it in GitHub Desktop.
Save lowe0292/fa3737fdabdff4059629 to your computer and use it in GitHub Desktop.
var Firebase = require('firebase');
var EmailService = require('./services/email');
var ref = new Firebase(process.env.FIREBASE_URL);
var firstLoad = true;
ref.authWithCustomToken(process.env.FIREBASE_SECRET, function (err) {
if (firstLoad) {
firstLoad = false;
// When a potential tenant submits an application, email out an alert
ref.child('applicants').on('child_added', function (snapshot) {
var applicant = snapshot.val();
if (!(applicant.alerts && applicant.alerts.apply)) {
var body = applicant.firstName + ' ' + applicant.lastName + '\n' + applicant.email + '\n' + applicant.phoneNumber;
EmailService
.send('New Applicant', 'alerts@domain.com', body)
.then(function () {
ref.child('applicants').child(snapshot.key()).child('alerts').child('apply').set(true);
});
}
});
}
});
@stites
Copy link

stites commented Feb 3, 2015

You said that if (!(applicant.alerts && applicant.alerts.apply)) guards against dupes — what is this output?

Also — have you tried putting a breakpoint/debugger on 18 and going through the stacktrace via node inspector/webstorm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment