Created
March 24, 2017 18:58
-
-
Save dypsilon/f7132292854395628b94a3cb48406118 to your computer and use it in GitHub Desktop.
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
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