Class: Cats::Core::RoundBeneficiariesController

Inherits:
ApplicationController show all
Includes:
Common
Defined in:
app/controllers/cats/core/round_beneficiaries_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

#confirm_receiptObject



34
35
36
37
38
39
40
# File 'app/controllers/cats/core/round_beneficiaries_controller.rb', line 34

def confirm_receipt
  service = BeneficiaryService.new
  result = service.confirm_receipt(params[:id], common_params[:ids])
  render json: {success: result}
rescue StandardError => e
  render json: {success: false, error: e.message}
end

#filterObject



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

def filter
  query = RoundBeneficiary.includes(:beneficiary, :commodity_category, :unit).ransack(params[:q])
  render json: {success: true, data: serialize(query.result)}
end

#generateObject



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

def generate
  service = BeneficiaryService.new
  result = service.generate_distribution_list(params[:id])
  render json: {success: result}
rescue StandardError => e
  render json: {success: false, error: e.message}
end

#indexObject



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

def index
  beneficiaries = RoundBeneficiary.joins(:round_plan_item)
                                  .where(round_plan_item: {round_plan_id: params[:id]})
                                  .includes(:beneficiary, :commodity_category, :unit)
  render json: {success: true, data: serialize(beneficiaries)}
end

#remove_beneficiariesObject



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

def remove_beneficiaries
  service = BeneficiaryService.new
  result = service.remove_items(params[:id], common_params[:ids])
  render json: {success: result}
rescue StandardError => e
  render json: {success: false, error: e.message}
end