Last active
August 4, 2016 17:54
-
-
Save daliborgogic/deaafdee6f090392dc4659e98096cc90 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
app.route('/users') | |
.post((req, res) => { | |
User.count({email: req.body.email}, function (err, count) { | |
if (count == 0) { | |
// email doesn't exist | |
const user = new User() | |
user.email = req.body.email | |
user.newsletter = req.body.newsletter | |
user.save((err) => { | |
if (err) | |
res.send(err) | |
res.json({message: 'User created'}) | |
io.emit('checkEmail', {check: 'User added'}) | |
}) | |
} else { | |
// email exists | |
User.find({email: req.body.email}, (err, users) => { | |
if (err) | |
res.send(err) | |
res.json(users[0]._id) | |
io.emit('checkEmail', {check: users[0]._id}) | |
}).limit(1) | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment