Class: SkuVariantsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sku_variants_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_variants_controller.rb', line 41

def create_or_update
  sku_variant_id = params[:sku_variant_id] || 0
  sku_variant_type = params[:sku_variant_type]
  description_english = params[:description_english]
  description_french = params[:description_french]
  active = params[:active]
  system_record = params[:system_record]
  created_by = params[:created_by] || 'Admin'
  modified_by = params[:modified_by] || 'Admin'

  SkuVariant.create_or_update_procedure(
    sku_variant_id: sku_variant_id,
    sku_variant_type: sku_variant_type,
    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 Variant inserted/updated successfully' }
end

#get_sku_variants_by_typeObject



65
66
67
68
69
# File 'app/controllers/sku_variants_controller.rb', line 65

def get_sku_variants_by_type
  sku_variant_type = params[:sku_variant_type]
  result = SkuVariant.get_sku_variants_by_type_procedure(sku_variant_type)
  render json: result
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
32
33
# File 'app/controllers/sku_variants_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_variant_id'
  order_direction = params[:order_direction] || 'DESC'
  grouping = "#{order_by} #{order_direction}"
  sku_variant_type = params.dig(:variant_type, :value)

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

  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



35
36
37
38
39
# File 'app/controllers/sku_variants_controller.rb', line 35

def show
  sku_variant_id = params[:id]
  result = SkuVariant.find_procedure(sku_variant_id)
  render json: result
end