Class: Decidim::BulletinBoard::Authority::StartVote

Inherits:
Command
  • Object
show all
Defined in:
lib/decidim/bulletin_board/authority/start_vote.rb

Overview

This command uses the GraphQL client to request the starting of the voting period.

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) ⇒ StartVote

Public: Initializes the command.

election_id - The local election identifier



11
12
13
# File 'lib/decidim/bulletin_board/authority/start_vote.rb', line 11

def initialize(election_id)
  @election_id = election_id
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

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

  • :error if query operation was not successful.

Returns nothing.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/decidim/bulletin_board/authority/start_vote.rb', line 26

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

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

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

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

#message_idObject

Returns the message_id related to the operation



16
17
18
# File 'lib/decidim/bulletin_board/authority/start_vote.rb', line 16

def message_id
  @message_id ||= build_message_id(unique_election_id(election_id), "start_vote")
end