Sha256: 1573b3036f1c982c11ebf9ca2aff63d0dbb27fb52b2fab9bd91094473cdaaab4

Contents?: true

Size: 1.08 KB

Versions: 50

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Admin
      # A command with all the business logic when an admin answers a proposal.
      class AnswerProposal < Rectify::Command
        # Public: Initializes the command.
        #
        # form - A form object with the params.
        # proposal - The proposal to write the answer for.
        def initialize(form, proposal)
          @form = form
          @proposal = proposal
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid.
        # - :invalid if the form wasn't valid and we couldn't proceed.
        #
        # Returns nothing.
        def call
          return broadcast(:invalid) if form.invalid?

          answer_proposal
          broadcast(:ok)
        end

        private

        attr_reader :form, :proposal

        def answer_proposal
          proposal.update_attributes!(
            state: @form.state,
            answer: @form.answer,
            answered_at: Time.current
          )
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
decidim-proposals-0.8.4 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.8.3 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.8.2 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.8.1 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.8.0 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.7.4 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.7.3 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.7.2 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.7.1 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.7.0 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.6.8 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-0.6.8 decidim-proposals/app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.6.7 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-0.6.7 decidim-proposals/app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.6.6 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-0.6.6 decidim-proposals/app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.6.5 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-0.6.5 decidim-proposals/app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-proposals-0.6.4 app/commands/decidim/proposals/admin/answer_proposal.rb
decidim-0.6.4 decidim-proposals/app/commands/decidim/proposals/admin/answer_proposal.rb