Class: Decidim::Debates::CreateDebateType
- Inherits:
-
Api::Types::BaseMutation
- Object
- Api::Types::BaseMutation
- Decidim::Debates::CreateDebateType
- Defined in:
- lib/decidim/api/mutations/create_debate_type.rb
Instance Method Summary collapse
- #authorized?(attributes:, locale:, toggle_translations:) ⇒ Boolean
- #resolve(attributes:, locale:, toggle_translations:) ⇒ Object
Instance Method Details
#authorized?(attributes:, locale:, toggle_translations:) ⇒ Boolean
35 36 37 38 39 40 41 |
# File 'lib/decidim/api/mutations/create_debate_type.rb', line 35 def (attributes:, locale:, toggle_translations:) unless super && allowed_to?(:create, :debate, Debate.new(component: current_component), { current_user:, current_component: }) raise Decidim::Api::Errors::MutationNotAuthorizedError, I18n.t("decidim.api.errors.unauthorized_mutation") end true end |
#resolve(attributes:, locale:, toggle_translations:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/decidim/api/mutations/create_debate_type.rb', line 15 def resolve(attributes:, locale:, toggle_translations:) set_locale(locale:, toggle_translations:) params = attributes.to_h.slice(:title, :description) params[:taxonomies] = Decidim::Taxonomy.where(organization: current_organization, id: attributes.to_h.fetch(:taxonomies, [])).pluck(:id) form = form(Decidim::Debates::DebateForm).from_params(params) Decidim::Debates::CreateDebate.call(form) do on(:ok) do |debate| return debate.reload end on(:invalid) do raise Decidim::Api::Errors::AttributeValidationError, form.errors end end end |