Class: Cats::Core::RoundPlansController

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

Instance Method Summary collapse

Methods included from Common

#create, #show, #update

Methods inherited from ApplicationController

#authenticate, #current_user, #skip_bullet

Instance Method Details

#approveObject



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

def approve
  plan = @service.approve(params[:id])
  render json: {success: true, data: serialize(plan)}
rescue StandardError => e
  render json: {success: false, error: e.message}, status: :unprocessable_entity
end

#filterObject



15
16
17
18
# File 'app/controllers/cats/core/round_plans_controller.rb', line 15

def filter
  query = RoundPlan.includes({plan: :program}, :region).ransack(params[:q])
  render json: {success: true, data: serialize(query.result)}
end

#generateObject



27
28
29
30
31
# File 'app/controllers/cats/core/round_plans_controller.rb', line 27

def generate
  p = model_params
  plan = @service.generate_round_plan(p[:reference_no], p[:rounds], p[:plan_id], p[:region_id])
  render json: {success: true, data: serialize(plan)}
end

#generate_round_needsObject



33
34
35
36
37
38
# File 'app/controllers/cats/core/round_plans_controller.rb', line 33

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

#indexObject



9
10
11
12
13
# File 'app/controllers/cats/core/round_plans_controller.rb', line 9

def index
  super do
    RoundPlan.includes({plan: :program}, :region).where(plan: params[:id])
  end
end

#remove_itemsObject



40
41
42
43
44
45
# File 'app/controllers/cats/core/round_plans_controller.rb', line 40

def remove_items
  plan = @service.remove_items(params[:id], remove_params[:ids])
  render json: {success: true, data: serialize(plan)}
rescue StandardError => e
  render json: {success: false, error: e.message}
end