Instantly share code, notes, and snippets.

Embed
What would you like to do?
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