Class: Decidim::Comments::CommentableMutationType

Inherits:
Api::Types::BaseObject show all
Defined in:
decidim-comments/lib/decidim/api/commentable_mutation_type.rb

Instance Method Summary collapse

Instance Method Details

#add_comment(body:, alignment: nil, user_group_id: nil) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
# File 'decidim-comments/lib/decidim/api/commentable_mutation_type.rb', line 16

def add_comment(body:, alignment: nil, user_group_id: nil)
  params = { "comment" => { "body" => body, "alignment" => alignment, "user_group_id" => user_group_id, "commentable" => object } }
  form = Decidim::Comments::CommentForm.from_params(params).with_context(
    current_organization: context[:current_organization],
    current_component: object.component
  )
  Decidim::Comments::CreateComment.call(form, context[:current_user]) do
    on(:ok) do |comment|
      return comment
    end
  end
end