Class: Decidim::BulletinBoard::Authority::CreateElection

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

Overview

This class handles the creation of an 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, election_data) ⇒ CreateElection

Returns a new instance of CreateElection.



8
9
10
11
# File 'lib/decidim/bulletin_board/authority/create_election.rb', line 8

def initialize(election_id, election_data)
  @election_id = election_id
  @election_data = election_data
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/decidim/bulletin_board/authority/create_election.rb', line 18

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

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

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

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

#message_idObject

Returns the message_id related to the operation



14
15
16
# File 'lib/decidim/bulletin_board/authority/create_election.rb', line 14

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