Created
June 26, 2018 17:42
-
-
Save nitish24p/4b6affe7564cd959ca3b4251637aa4db to your computer and use it in GitHub Desktop.
Async await
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.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