Sha256: 7e39564155c03a925a3f3d00a6cb38eb210fce6f2cfcab3724771a8d6f472864

Contents?: true

Size: 1.5 KB

Versions: 19

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    module Voter
      # This command allows the user to register an in person vote.
      class InPersonVote < Rectify::Command
        # Public: Initializes the command.
        #
        # form - A form with necessary info to register an in person vote.
        def initialize(form)
          @form = form
        end

        # Store and register the in person vote in the bulletin board
        #
        # Broadcasts :ok if successful, :invalid otherwise
        def call
          return broadcast(:invalid) if form.invalid?

          transaction do
            register_in_person_vote
          end

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

        private

        attr_reader :form, :in_person_vote

        delegate :bulletin_board, to: :form

        def register_in_person_vote
          bulletin_board.in_person_vote(form.election_id, form.voter_id, form.polling_station_slug) do |message_id|
            create_in_person_vote(message_id)
          end
        end

        def create_in_person_vote(message_id)
          @in_person_vote = Decidim::Votings::InPersonVote.create!(
            election: form.election,
            polling_station: form.polling_station,
            polling_officer: form.polling_officer,
            message_id: message_id,
            voter_id: form.voter_id,
            status: :pending
          )
        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/in_person_vote.rb
decidim-elections-0.26.9 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.26.8 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.26.7 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.26.5 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.26.4 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.26.3 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.26.2 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.26.1 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.26.0 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.26.0.rc2 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.26.0.rc1 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.25.2 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.25.1 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.25.0 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.25.0.rc4 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.25.0.rc3 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.25.0.rc2 app/commands/decidim/votings/voter/in_person_vote.rb
decidim-elections-0.25.0.rc1 app/commands/decidim/votings/voter/in_person_vote.rb