Created
June 26, 2018 17:23
-
-
Save nitish24p/97d176e667757d87a885c0e230545fcf to your computer and use it in GitHub Desktop.
User promise
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
exports.createOrAddUserPromise = (req, res, next) => { | |
User.findUserPromise(req.body) | |
.then(user => { | |
if (user) { | |
const existingUser = new User(user); | |
return newUser.updatePromise(req.body) | |
} | |
const newUser = new User(); | |
return newUser.savePromise(req.body); | |
}) | |
.then(data => res.send(data)) | |
.catch(e => next(e)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment