Class: Decidim::BulletinBoard::Voter::CastVote
- Defined in:
- lib/decidim/bulletin_board/voter/cast_vote.rb
Overview
This command uses the GraphQL client to cast the vote.
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(election_id, voter_id, encrypted_vote) ⇒ CastVote
constructor
Public: Initializes the command.
-
#message_id ⇒ Object
Returns the message_id related to the operation.
Methods inherited from Command
#build_message_id, #complete_message, #configure, #sign_message, #unique_election_id
Constructor Details
#initialize(election_id, voter_id, encrypted_vote) ⇒ CastVote
Public: Initializes the command.
election_id - The local election identifier voter_id - The unique identifier of the voter encrypted_vote - The content of the encrypted vote.
13 14 15 16 17 |
# File 'lib/decidim/bulletin_board/voter/cast_vote.rb', line 13 def initialize(election_id, voter_id, encrypted_vote) @election_id = election_id @voter_id = voter_id @encrypted_vote = encrypted_vote end |
Instance Method Details
#call ⇒ Object
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/cast_vote.rb', line 30 def call # arguments used inside the graphql operation args = { message_id:, signed_data: (, { content: encrypted_vote }) } begin response = graphql.query do mutation do vote(messageId: args[:message_id], signedData: args[:signed_data]) do pendingMessage do status end error end end end return broadcast(:error, response.data.vote.error) if response.data.vote.error.present? broadcast(:ok, response.data.vote.) rescue Graphlient::Errors::FaradayServerError broadcast(:error, "something went wrong") end end |
#message_id ⇒ Object
Returns the message_id related to the operation
20 21 22 |
# File 'lib/decidim/bulletin_board/voter/cast_vote.rb', line 20 def @message_id ||= (unique_election_id(election_id), "vote.cast", voter_id) end |