Sha256: 9eaee9af6a928212f121dada64957617edd8a371cfb3c5c63e1cf5d4ea373458

Contents?: true

Size: 1.27 KB

Versions: 19

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    module Voter
      # This command updates the in person vote status
      class UpdateInPersonVoteStatus < Rectify::Command
        # Public: Initializes the command.
        #
        # in_person_vote     - the in person vote that has been updated
        def initialize(in_person_vote)
          @in_person_vote = in_person_vote
        end

        # Update status and send notification
        #
        # Broadcasts :ok if successful, :invalid otherwise
        def call
          return broadcast(:ok) unless status_changed?

          transaction do
            update_vote_status
          end

          broadcast(:ok)
        rescue StandardError => e
          broadcast(:invalid, e.message)
        end

        private

        attr_reader :in_person_vote, :locale

        def status_changed?
          in_person_vote.status != vote_status
        end

        def bulletin_board
          @bulletin_board ||= Decidim::Elections.bulletin_board
        end

        def vote_status
          @vote_status ||= bulletin_board.get_pending_message_status(in_person_vote.message_id)
        end

        def update_vote_status
          in_person_vote.update!(status: vote_status)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-elections-0.26.10 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.26.9 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.26.8 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.26.7 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.26.5 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.26.4 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.26.3 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.26.2 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.26.1 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.26.0 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.26.0.rc2 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.26.0.rc1 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.25.2 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.25.1 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.25.0 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.25.0.rc4 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.25.0.rc3 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.25.0.rc2 app/commands/decidim/votings/voter/update_in_person_vote_status.rb
decidim-elections-0.25.0.rc1 app/commands/decidim/votings/voter/update_in_person_vote_status.rb