Created
March 24, 2017 19:11
-
-
Save dypsilon/b500cd1192114db887bf565ecc3ae249 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) => ({ isAllowed, post })); | |
}).then((input) => { | |
if (!input.isAllowed) { | |
return Promise.reject( | |
new Error('The user is not allowed to comment on this post.') | |
); | |
} | |
return insertComment(input.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