Last active
July 8, 2017 11:25
-
-
Save Amberlamps/27c5519caa14ac46a1d44d9440a3fa4f to your computer and use it in GitHub Desktop.
going full circle 0
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
app.post('/comments', (req, res, next) => { | |
try { | |
const { userId, postId } = req.body; | |
const comment = db.createCommentSync(req.body); | |
const post = db.getPostSync(postId); | |
db.updatePostSync(postId, { comments: post.comments + 1 }); | |
const user = db.getUserSync(userId); | |
db.updateUserSync(userId, { lastComment: comment.id }); | |
res.json(comment); | |
} catch (error) { | |
next(error); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment