Class: Decidim::BulletinBoard::Voter::GetPendingMessageStatus

Inherits:
Command
  • Object
show all
Defined in:
lib/decidim/bulletin_board/voter/get_pending_message_status.rb

Overview

This command uses the GraphQL client to get the status of a specific pending message.

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(message_id) ⇒ GetPendingMessageStatus

Public: Initializes the command.

form - A form object with the params.



11
12
13
# File 'lib/decidim/bulletin_board/voter/get_pending_message_status.rb', line 11

def initialize(message_id)
  @message_id = message_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 the form wasn’t valid or the query operation was not successful.

Returns nothing.



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

def call
  message_id = @message_id

  begin
    response = graphql.query do
      query do
        pendingMessage(messageId: message_id) do
          status
        end
      end
    end

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