Created
March 24, 2017 19:04
-
-
Save dypsilon/31287e84f57487f52212edd0f9b64954 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) { | |
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