Skip to content

Instantly share code, notes, and snippets.

@dypsilon
Created March 24, 2017 18:58
Show Gist options
  • Save dypsilon/f7132292854395628b94a3cb48406118 to your computer and use it in GitHub Desktop.
Save dypsilon/f7132292854395628b94a3cb48406118 to your computer and use it in GitHub Desktop.
function addComment(comment, done) {
fetchPostBySlug(comment.postSlug, (err, post) => {
if (err) return done(err);
if (!post.isCommentingEnabled) {
return done(new Error('Commenting is disabled.'));
}
isUserAllowedToComment(post, comment.user, (err, isAllowed) => {
if (err) return done(err);
if (!isAllowed) {
return done(
new Error('The user is not allowed to comment on this post.')
);
}
insertComment(post.id, comment.user, comment.message, (err, result) => {
if (err) return done(err);
return done(null, result.record);
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment