Class: Cats::Core::DispatchPlansController
Instance Method Summary
collapse
Methods included from Common
#show, #update
#authenticate, #current_user, #skip_bullet
Instance Method Details
#approve ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'app/controllers/cats/core/dispatch_plans_controller.rb', line 57
def approve
service = DispatchPlanService.new
plan = DispatchPlan.find(params[:id])
plan = service.approve(plan)
render json: {success: true, data: serialize(plan)}
rescue StandardError => e
render json: {success: false, error: e.message}
end
|
#bulk_create ⇒ Object
51
52
53
54
55
|
# File 'app/controllers/cats/core/dispatch_plans_controller.rb', line 51
def bulk_create
service = DispatchPlanService.new
plan = service.bulk_create(bulk_create_params, current_user)
render json: {success: true, data: serialize(plan)}
end
|
#create ⇒ Object
37
38
39
40
41
42
43
|
# File 'app/controllers/cats/core/dispatch_plans_controller.rb', line 37
def create
service = DispatchPlanService.new
plan = service.create(model_params, current_user)
render json: {success: true, data: serialize(plan)}, status: :created
rescue StandardError => e
render json: {success: false, error: e.message}, status: :unprocessable_entity
end
|
#filter ⇒ Object
32
33
34
35
|
# File 'app/controllers/cats/core/dispatch_plans_controller.rb', line 32
def filter
query = DispatchPlan.ransack(params[:q])
render json: {success: true, data: serialize(query.result)}
end
|
#generate ⇒ Object
45
46
47
48
49
|
# File 'app/controllers/cats/core/dispatch_plans_controller.rb', line 45
def generate
service = DispatchPlanService.new
items = service.generate(params[:id])
render json: {success: true, data: serialize(items)}
end
|
#index ⇒ Object
6
7
8
9
10
|
# File 'app/controllers/cats/core/dispatch_plans_controller.rb', line 6
def index
super do
DispatchPlan.all.includes(:dispatchable)
end
end
|
#plans_for_location ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/controllers/cats/core/dispatch_plans_controller.rb', line 17
def plans_for_location
if params[:location_type] == "source"
plans = DispatchPlan.includes([:dispatchable]).joins(:dispatch_plan_items)
.where(status: Cats::Core::DispatchPlan::APPROVED,
upstream: false,
dispatch_plan_items: {source_id: params[:location_id]}).uniq
elsif params[:location_type] == "destination"
plans = DispatchPlan.includes([:dispatchable]).joins(:dispatch_plan_items)
.where(status: Cats::Core::DispatchPlan::APPROVED,
upstream: false,
dispatch_plan_items: {destination_id: params[:location_id]}).uniq
end
render json: {success: true, data: serialize(plans)}
end
|
#plans_for_user ⇒ Object
12
13
14
15
|
# File 'app/controllers/cats/core/dispatch_plans_controller.rb', line 12
def plans_for_user
plans = DispatchPlan.where(prepared_by: current_user).includes(:dispatchable)
render json: {success: true, data: serialize(plans)}
end
|