Class: SkuGroupsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sku_groups_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

#create_or_updateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/sku_groups_controller.rb', line 41

def create_or_update
  sku_group_id = params[:sku_group_id] || 0
  code = params[:code]
  description_english = params[:description_english]
  description_french = params[:description_french]
  active = params[:active]
  system_record = params[:system_record]
  created_by = params[:created_by]
  modified_by = params[:modified_by]

  SkuGroup.create_or_update_procedure(
    sku_group_id: sku_group_id,
    code: code,
    description_english: description_english,
    description_french: description_french,
    active: active,
    system_record: system_record,
    created_by: created_by,
    modified_by: modified_by
  )

  render json: { message: 'SKU Group inserted/updated successfully' }
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/sku_groups_controller.rb', line 6

def index
  display_length = params[:limit] || 10
  search_value = params[:query] || ''
  display_start_from_page_no = params[:offset] || 1
  order_by = params[:order_by] || 'sku_group_id'
  order_direction = params[:order_direction] || 'DESC'
  grouping = "#{order_by} #{order_direction}"

  result = SkuGroup.where_procedure(
    display_length: display_length,
    search_value: search_value,
    display_start_from_page_no: display_start_from_page_no,
    grouping: grouping
  )

  result[:data] = result[:data].map do |row|
    row.merge(
      'type_description' => I18n.locale == :fr ? row['description_french'] : row['description_english']
    )
  end

  render json: {
    data: result[:data],
    metadata: result[:metadata]
  }
end

#showObject



33
34
35
36
37
38
39
# File 'app/controllers/sku_groups_controller.rb', line 33

def show
  sku_group_id = params[:id]
  result = SkuGroup.find_procedure(sku_group_id).as_json(
    methods: [:type_description]
  )
  render json: result
end