Skip to content

Instantly share code, notes, and snippets.

@nitish24p
Created June 26, 2018 17:23
Show Gist options
  • Save nitish24p/97d176e667757d87a885c0e230545fcf to your computer and use it in GitHub Desktop.
Save nitish24p/97d176e667757d87a885c0e230545fcf to your computer and use it in GitHub Desktop.
User promise
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