Sha256: 26293dbe8d1932e4f88d5b70363273acc788de5c865e6f77e5df1de3657d293d

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module Decidim
  module BulletinBoard
    module Authority
      # This class handles the creation of an election.
      class CreateElection < Decidim::BulletinBoard::Command
        def initialize(election_id, election_data)
          @election_id = election_id
          @election_data = election_data
        end

        # Returns the message_id related to the operation
        def message_id
          @message_id ||= build_message_id(unique_election_id(election_id), "create_election")
        end

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

          response = client.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

        private

        attr_reader :election_data, :election_id
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-bulletin_board-0.9.2 lib/decidim/bulletin_board/authority/create_election.rb
decidim-bulletin_board-0.9.1 lib/decidim/bulletin_board/authority/create_election.rb
decidim-bulletin_board-0.9.0 lib/decidim/bulletin_board/authority/create_election.rb