Skip to content

Instantly share code, notes, and snippets.

@dypsilon
Created March 24, 2017 19:15
Show Gist options
  • Save dypsilon/353e41e1b501fec45d7d2569f541bcd9 to your computer and use it in GitHub Desktop.
Save dypsilon/353e41e1b501fec45d7d2569f541bcd9 to your computer and use it in GitHub Desktop.
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