Skip to content

Instantly share code, notes, and snippets.

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