Skip to content

Instantly share code, notes, and snippets.

@Amberlamps
Last active July 8, 2017 11:25
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 Amberlamps/27c5519caa14ac46a1d44d9440a3fa4f to your computer and use it in GitHub Desktop.
Save Amberlamps/27c5519caa14ac46a1d44d9440a3fa4f to your computer and use it in GitHub Desktop.
going full circle 0
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