Skip to content

Instantly share code, notes, and snippets.

@nitish24p
Created June 26, 2018 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitish24p/4b6affe7564cd959ca3b4251637aa4db to your computer and use it in GitHub Desktop.
Save nitish24p/4b6affe7564cd959ca3b4251637aa4db to your computer and use it in GitHub Desktop.
Async await
exports.createOrAddUserAsync = async (req, res, next) => {
try {
const user = await User.findUserPromise(req.body);
if (user) {
const existingUser = new User(user);
const data = await existingUser.updatePromise(req.body);
return res.send(data);
}
const newUser = new User();
const data = await newUser.savePromise(req.body);
return res.send(data);
} catch (e) {
return next(e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment