Skip to content

Instantly share code, notes, and snippets.

@wgottschalk-RMS
Last active July 1, 2016 02:44
Show Gist options
  • Save wgottschalk-RMS/274792639a031fd51eaf418dc7ff1332 to your computer and use it in GitHub Desktop.
Save wgottschalk-RMS/274792639a031fd51eaf418dc7ff1332 to your computer and use it in GitHub Desktop.
// all asynchronous methods have been promisified
app.post("/purchase", (req, res) => {
user.findOneAsync(req.body)
.then( userData => permissions.findAllAsync(userData) )
.then( permissions => {
if (isAllowed(permissions)) {
return transaction.processAsync(userData);
// userData is not defined! It's not in the proper scope!
}
})
.then( confirmNum => res.send("Your purchase was successful!") )
.catch( err => handleError(err) )
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment