Instantly share code, notes, and snippets.

What would you like to do?
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(, 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