Class: Logistics::Core::OperationsController

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

Instance Method Summary collapse

Instance Method Details

#assignObject



75
76
77
78
# File 'app/controllers/logistics/core/operations_controller.rb', line 75

def assign
  response = @service.assign_owner(assign_params[:payload])
  render json: response
end

#assignedObject



61
62
63
64
65
66
# File 'app/controllers/logistics/core/operations_controller.rb', line 61

def assigned
  operations = Operation.where.not(owner_id: nil)
  data = ApplicationRecord.as_json(operations)
  response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
  render json: response
end

#createObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/logistics/core/operations_controller.rb', line 24

def create
  service = OperationService.new
  result, @operation = service.save(model_params)
  if result
    response = Mks::Common::MethodResponse.new(true, 'Operation saved successfully!', @operation, nil, nil)
  else
    errors = Mks::Common::Util.error_messages @operation, 'Operation'
    response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
  end
  render json: response
end

#filter_fresh_by_clientObject



54
55
56
57
58
59
# File 'app/controllers/logistics/core/operations_controller.rb', line 54

def filter_fresh_by_client
  operations = Operation.joins(:offer_request).fresh.where('logistics_core_offer_requests.client_id = ?', params[:id])
  data = ApplicationRecord.as_json(operations)
  response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
  render json: response
end

#freshObject



47
48
49
50
51
52
# File 'app/controllers/logistics/core/operations_controller.rb', line 47

def fresh
  operations = Operation.fresh
  data = ApplicationRecord.as_json(operations)
  response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
  render json: response
end

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/logistics/core/operations_controller.rb', line 7

def index
  if params.key?('simple')
    operations = Operation.includes(:owner, {offer_request: :client}).order('id DESC')
    data = Logistics::Core::ApplicationRecord.as_json(operations, SimpleOperationSerializer)
  else
    operations = Operation.includes(:declarant, :declaration_type, :transport_mode,
                                    :customs_office, :customs_office_unit, :country_of_origin,
                                    :acquisition_mode, :payment_term, :delivery_term,
                                    :container_arrangement, :customs_transport_tariff,
                                    :esl_transport_tariff, :warehouse, :owner, :offer_request).order('id DESC')
    data = Logistics::Core::ApplicationRecord.as_json(operations)
  end

  response = {success: true, data: data}
  render json: response
end

#unassignedObject



68
69
70
71
72
73
# File 'app/controllers/logistics/core/operations_controller.rb', line 68

def unassigned
  operations = Operation.where(owner_id: nil)
  data = ApplicationRecord.as_json(operations)
  response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
  render json: response
end

#updateObject



36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/logistics/core/operations_controller.rb', line 36

def update
  operation = Operation.find(params[:id])
  update_attributes(operation, model_params)
  if operation.save
    response = Mks::Common::MethodResponse.new(true, 'Operation updated successfully!', nil, nil, nil)
  else
    response = Mks::Common::MethodResponse.new(false, nil, nil, ['Operation update failed!'], nil)
  end
  render json: response
end