Class: Decidim::BulletinBoard::Voter::InPersonVote

Inherits:
Command
  • Object
show all
Defined in:
lib/decidim/bulletin_board/voter/in_person_vote.rb

Overview

This command uses the GraphQL client to inform about a vote casted in person in a polling station.

Instance Attribute Summary

Attributes inherited from Command

#graphql, #settings

Instance Method Summary collapse

Methods inherited from Command

#build_message_id, #complete_message, #configure, #sign_message, #unique_election_id

Constructor Details

#initialize(election_id, voter_id, polling_station_id) ⇒ InPersonVote

Public: Initializes the command.

election_id - The local election identifier voter_id - The unique identifier of the voter polling_station_id - The identifier of the polling station where the vote was casted.



13
14
15
16
17
# File 'lib/decidim/bulletin_board/voter/in_person_vote.rb', line 13

def initialize(election_id, voter_id, polling_station_id)
  @election_id = election_id
  @voter_id = voter_id
  @polling_station_id = polling_station_id
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid and the mutation operation is successful.

  • :error if the form wasn’t valid or the mutation operation was not successful.

Returns nothing.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/decidim/bulletin_board/voter/in_person_vote.rb', line 30

def call
  # arguments used inside the graphql operation
  args = {
    message_id:,
    signed_data: sign_message(message_id, { polling_station_id: })
  }

  begin
    response = graphql.query do
      mutation do
        vote(messageId: args[:message_id], signedData: args[:signed_data]) do
          pendingMessage do
            messageId
            status
          end
          error
        end
      end
    end

    return broadcast(:error, response.data.vote.error) if response.data.vote.error.present?

    broadcast(:ok, response.data.vote.pending_message)
  rescue Graphlient::Errors::FaradayServerError
    broadcast(:error, "something went wrong")
  end
end

#message_idObject

Returns the message_id related to the operation



20
21
22
# File 'lib/decidim/bulletin_board/voter/in_person_vote.rb', line 20

def message_id
  @message_id ||= build_message_id(unique_election_id(election_id), "vote.in_person", voter_id)
end