houdini/app/controllers/campaigns/campaign_gift_options_controller.rb

65 lines
2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-11-09 00:29:00 +00:00
2020-06-12 20:03:43 +00:00
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
module Campaigns
class CampaignGiftOptionsController < ApplicationController
include Controllers::Campaign::Current
include Controllers::Campaign::Authorization
before_action :authenticate_campaign_editor!, only: %i[create destroy update update_order report]
def report
respond_to do |format|
format.json do
render json: QueryCampaignGifts.report_metrics(current_campaign.id)
end
end
end
def index
@gift_options = current_campaign.campaign_gift_options.order('"order", amount_recurring, amount_one_time')
render json: { data: @gift_options }
end
def show
render json: { data: current_campaign.campaign_gift_options.find(params[:id]) }
end
def create
campaign = current_campaign
2019-10-29 19:05:59 +00:00
json_saved CreateCampaignGiftOption.create(campaign, campaign_gift_option_params),
'Gift option successfully created!'
end
def update
@campaign = current_campaign
gift_option = @campaign.campaign_gift_options.find params[:id]
2019-10-29 19:05:59 +00:00
json_saved UpdateCampaignGiftOption.update(gift_option, campaign_gift_option_params), 'Successfully updated'
end
# put /nonprofits/:nonprofit_id/campaigns/:campaign_id/campaign_gift_options/update_order
# Pass in {data: [{id: 1, order: 1}]}
def update_order
2019-10-29 19:05:59 +00:00
updated_gift_options = UpdateOrder.with_data('campaign_gift_options', update_order_params)
render json: updated_gift_options
end
def destroy
@campaign = current_campaign
render_json { DeleteCampaignGiftOption.delete(@campaign, params[:id]) }
end
2019-10-29 19:05:59 +00:00
private
2019-10-29 19:05:59 +00:00
def campaign_gift_option_params
params.require(:campaign_gift_option).permit(:name, :amount_one_time, :amount_recurring, :description, :quantity, :to_ship, :order, :hide_contributions)
end
def update_order_params
params.require(:data)
end
end
2019-10-29 19:05:59 +00:00
end