Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. async function addComment(comment) {
  2. const post = await fetchPostBySlug(comment.postSlug);
  3.  
  4. if (!post.isCommentingEnabled) {
  5. throw new Error('Commenting is disabled.');
  6. }
  7.  
  8. const isAllowed = await isUserAllowedToComment(post, comment.user);
  9.  
  10. if (!isAllowed) {
  11. throw new Error('The user is not allowed to comment on this post.');
  12. }
  13.  
  14. const result = await insertComment(post.id, comment.user, comment.message);
  15.  
  16. return result.record;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement