Class: Logistics::Core::DeclarationTypesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/logistics/core/declaration_types_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/logistics/core/declaration_types_controller.rb', line 21

def create
  @declaration_type = DeclarationType.new(declaration_type_params)
  if @declaration_type.save
    response = Mks::Common::MethodResponse.new(true, 'Declaration type saved successfully!', @declaration_type, nil, nil)
  else
    errors = Mks::Common::Util.error_messages @declaration_type, 'Declaration type'
    response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
  end
  render json: response
end

#filter_by_transaction_typeObject



13
14
15
16
17
18
19
# File 'app/controllers/logistics/core/declaration_types_controller.rb', line 13

def filter_by_transaction_type
  declaration_types = DeclarationType.includes(:transaction_type)
                                     .where(transaction_type_id: params[:id])
  data = ApplicationRecord.as_json(declaration_types)
  response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
  render json: response
end

#indexObject



6
7
8
9
10
11
# File 'app/controllers/logistics/core/declaration_types_controller.rb', line 6

def index
  declaration_types = DeclarationType.includes(:transaction_type)
  data = ApplicationRecord.as_json(declaration_types)
  response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
  render json: response
end

#updateObject



32
33
34
35
36
37
38
39
40
# File 'app/controllers/logistics/core/declaration_types_controller.rb', line 32

def update
  if @declaration_type.update(declaration_type_params)
    response = Mks::Common::MethodResponse.new(true, "Declaration type updated successfully!", @declaration_type, nil, nil)
  else
    errors = Mks::Common::Util.error_messages @declaration_type, "Declaration type"
    response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
  end
  render json: response
end