Created
March 24, 2017 19:15
-
-
Save dypsilon/353e41e1b501fec45d7d2569f541bcd9 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
async function addComment(comment) { | |
const post = await fetchPostBySlug(comment.postSlug); | |
if (!post.isCommentingEnabled) { | |
throw new Error('Commenting is disabled.'); | |
} | |
const isAllowed = await isUserAllowedToComment(post, comment.user); | |
if (!isAllowed) { | |
throw new Error('The user is not allowed to comment on this post.'); | |
} | |
const result = await insertComment(post.id, comment.user, comment.message); | |
return result.record; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment