Class: HasuraHandler::ActionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/hasura_handler/actions_controller.rb

Instance Method Summary collapse

Instance Method Details

#action_paramsObject



22
23
24
25
26
27
28
# File 'app/controllers/hasura_handler/actions_controller.rb', line 22

def action_params
  params.permit(
    action: [:name],
    input: {},
    session_variables: {}
  )
end

#processObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/hasura_handler/actions_controller.rb', line 5

def process
  unless HasuraHandler::Action.hasura_actions.keys.include?(action_params[:action][:name])
    render json: { error: true, message: 'action name not registered' }, status: 404
    return
  end

  klass = HasuraHandler::Action.hasura_actions[action_params[:action][:name]]
  action = klass.new(action_params[:session_variables], action_params[:input])
  action.run

  if action.error_message.present?
    render json: { error: true, message: action.error_message }, status: 400
  else
    render json: action.output
  end
end