Class: Cats::Core::DispatchesController

Inherits:
ApplicationController show all
Includes:
Common
Defined in:
app/controllers/cats/core/dispatches_controller.rb

Instance Method Summary collapse

Methods included from Common

#show, #update

Methods inherited from ApplicationController

#authenticate, #current_user, #skip_bullet

Instance Method Details

#approveObject



29
30
31
32
33
34
35
# File 'app/controllers/cats/core/dispatches_controller.rb', line 29

def approve
  dispatch = set_object
  dispatch.approve
  render json: {success: true, data: serialize(dispatch)}
rescue StandardError => e
  render json: {success: false, error: e.message}
end

#commodityObject



74
75
76
77
# File 'app/controllers/cats/core/dispatches_controller.rb', line 74

def commodity
  data = set_object.dispatch_plan_item.commodity
  render json: {success: true, data: serialize(data)}
end

#confirmObject



51
52
53
54
55
56
57
# File 'app/controllers/cats/core/dispatches_controller.rb', line 51

def confirm
  dispatch = set_object
  dispatch.confirm
  render json: {success: true, data: serialize(dispatch)}
rescue StandardError => e
  render json: {success: false, error: e.message}
end

#createObject



20
21
22
23
24
25
26
27
# File 'app/controllers/cats/core/dispatches_controller.rb', line 20

def create
  super do
    dispatch = Dispatch.new(model_params)
    dispatch.dispatch_status = Dispatch::DRAFT
    dispatch.prepared_by = current_user
    dispatch
  end
end

#filterObject



59
60
61
62
63
64
65
66
67
# File 'app/controllers/cats/core/dispatches_controller.rb', line 59

def filter
  query = Dispatch.includes(
    {dispatch_plan_item: :destination},
    :transporter,
    :prepared_by,
    :unit
  ).ransack(params[:q])
  render json: {success: true, data: serialize(query.result.reverse_order)}
end

#indexObject



9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/cats/core/dispatches_controller.rb', line 9

def index
  super do
    Dispatch.includes(
      {dispatch_plan_item: :destination},
      :transporter,
      :prepared_by,
      :unit
    ).where(dispatch_plan_item_id: params[:id]).reverse_order
  end
end

#revertObject



79
80
81
82
83
84
# File 'app/controllers/cats/core/dispatches_controller.rb', line 79

def revert
  data = set_object.revert
  render json: {success: true, data: serialize(data)}
rescue StandardError => e
  render json: {success: false, error: e.message}
end

#searchObject



69
70
71
72
# File 'app/controllers/cats/core/dispatches_controller.rb', line 69

def search
  data = @service.search(current_user, params[:status])
  render json: {success: true, data: serialize(data)}
end

#startObject



37
38
39
40
41
42
# File 'app/controllers/cats/core/dispatches_controller.rb', line 37

def start
  dispatch = @service.start(set_object)
  render json: {success: true, data: serialize(dispatch)}
rescue StandardError => e
  render json: {success: false, error: e.message}
end

#start_with_pinObject



44
45
46
47
48
49
# File 'app/controllers/cats/core/dispatches_controller.rb', line 44

def start_with_pin
  dispatch = @service.start_with_pin(params[:id], start_with_pin_params[:pin])
  render json: {success: true, data: serialize(dispatch)}
rescue StandardError => e
  render json: {success: false, error: e.message}
end