Class: ReportsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper
Defined in:
app/controllers/reports_controller.rb

Instance Method Summary collapse

Methods included from AuthentificationHelper

#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token

Instance Method Details

#indexObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
# File 'app/controllers/reports_controller.rb', line 15

def index
  query = params[:query] || ''
  order = params[:order] || 'desc'
  order_by = params[:orderBy] || 'report_id'
  limit = params[:limit] || 100
  offset = params[:offset] || 0
  tag_ids = params[:tag_ids] || []

  reports = Report.where(active: true).available_for_company(current_company_id).for_tags(tag_ids).includes(:tags)

  data,  = fetch_records(
    records: reports,
    order_by: order_by,
    order: order,
    query: query,
    limit: limit,
    offset: offset,
    search_fields: Report.search_fields,
    fields: %i[
      report_id
      slug
      active
    ]
  ).values_at(:data, :metadata)

  data = data.as_json(
    methods: %i[
      name
      description
    ],
    include: [
      :tags
    ]
  )

  render json: {
    data: data,
    metadata: 
  }
end

#infoObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/reports_controller.rb', line 56

def info
  slug = params[:slug]
  report = @reports.find_by(slug: slug)

  data = report.as_json(
    methods: %i[
      name
      description
    ],
    include: [
      :tags
    ]
  )

  render json: {
    data: data
  }
end