Class: Aviate::EngineController

Inherits:
Kaui::EngineController
  • Object
show all
Defined in:
app/controllers/aviate/engine_controller.rb

Direct Known Subclasses

ConfigurationController, WalletsController

Instance Method Summary collapse

Instance Method Details

#as_string(error) ⇒ Object



7
8
9
10
11
12
13
14
# File 'app/controllers/aviate/engine_controller.rb', line 7

def as_string(error)
  if error.is_a?(KillBillClient::API::ResponseError)
    "Error #{error.response.code}: #{as_string_from_response(error.response.body)}"
  else
    log_rescue_error(error)
    error.message
  end
end

#aviate_authenticationObject



59
60
61
62
63
64
65
# File 'app/controllers/aviate/engine_controller.rb', line 59

def aviate_authentication
  available = Killbill::Aviate::AviateClient.aviate_plugin_available?(options_for_klient)
  return if available.first

  flash[:error] = t('flashes.errors.wallet_authentication_failed')
  redirect_to aviate_engine.aviate_root_path
end

#current_tenant_userObject



24
25
26
27
# File 'app/controllers/aviate/engine_controller.rb', line 24

def current_tenant_user
  user = current_user if respond_to?(:current_user)
  Aviate.current_tenant_user.call(session, user)
end

#external_paginate(account_id, searcher, formatter) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/aviate/engine_controller.rb', line 29

def external_paginate(, searcher, formatter)
  search_key = (params[:search] || {})[:value].presence
  data = []
  begin
    pages = searcher.call(search_key)
    if pages.any?
      pages.each do |page|
        page['wallet_path'] = aviate_engine.(, page['walletId'])
        data << formatter.call(page)
      end
    end
  rescue StandardError => e
    error = e.to_s
  end

  json = {
    draw: (params[:draw] || 0).to_i,
    recordsTotal: pages.nil? ? 0 : SIMPLE_PAGINATION_THRESHOLD,
    recordsFiltered: pages.nil? ? 0 : SIMPLE_PAGINATION_THRESHOLD,
    data: data,
    columns: []
  }

  json[:error] = error unless error.nil?

  respond_to do |format|
    format.json { render json: json }
  end
end

#layoutObject



20
21
22
# File 'app/controllers/aviate/engine_controller.rb', line 20

def layout
  Aviate.config[:layout]
end

#log_rescue_error(error) ⇒ Object



16
17
18
# File 'app/controllers/aviate/engine_controller.rb', line 16

def log_rescue_error(error)
  Rails.logger.warn "#{error.class} #{error.message}. #{error.backtrace.join("\n")}"
end