Sha256: 61a62ec8775e9c6eb50a2aebf82f6f988848e1a2b672cced568672dd1dc7f46b

Contents?: true

Size: 943 Bytes

Versions: 63

Compression:

Stored size: 943 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Consultations
    # A command with all the business logic when a user unvotes a question.
    class UnvoteQuestion < Rectify::Command
      # Public: Initializes the command.
      #
      # question   - A Decidim::Consultations::Question object.
      # current_user - The current user.
      def initialize(question, current_user)
        @question = question
        @current_user = current_user
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid, together with the question.
      # - :invalid if the form wasn't valid and we couldn't proceed.
      #
      # Returns nothing.
      def call
        destroy_vote
        broadcast(:ok, @question)
      end

      private

      def destroy_vote
        @question
          .votes
          .where(author: @current_user)
          .destroy_all
      end
    end
  end
end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
decidim-consultations-0.26.10 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.26.9 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.26.8 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.26.7 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.26.5 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.26.4 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.26.3 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.26.2 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.26.1 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.26.0 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.26.0.rc2 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.26.0.rc1 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.25.2 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.25.1 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.25.0 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.25.0.rc4 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.25.0.rc3 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.25.0.rc2 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.25.0.rc1 app/commands/decidim/consultations/unvote_question.rb
decidim-consultations-0.24.3 app/commands/decidim/consultations/unvote_question.rb