Created
January 29, 2015 15:23
-
-
Save lowe0292/fa3737fdabdff4059629 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
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); | |
}); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?