Class: Decidim::BulletinBoard::Authority::GetElectionStatus

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

Overview

This command uses the GraphQL client to get the status of the election.

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

Public: Initializes the command.

election_id - The local election identifier



11
12
13
# File 'lib/decidim/bulletin_board/authority/get_election_status.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.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/decidim/bulletin_board/authority/get_election_status.rb', line 21

def call
  # arguments used inside the graphql operation
  args = {
    unique_id: unique_election_id(election_id)
  }

  response = graphql.query do
    query do
      election(uniqueId: args[:unique_id]) do
        status
      end
    end
  end

  broadcast(:ok, response.data.election.status)
rescue Graphlient::Errors::ServerError
  broadcast(:error, "Sorry, something went wrong")
end