2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
class CampaignGiftOptionsController < ApplicationController
|
2018-08-08 21:31:42 +00:00
|
|
|
include Controllers::CampaignHelper
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-13 07:53:59 +00:00
|
|
|
before_action :authenticate_campaign_editor!, only: [:create, :destroy, :update, :update_order]
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
json_saved CreateCampaignGiftOption.create(campaign, params[:campaign_gift_option]),
|
|
|
|
'Gift option successfully created!'
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@campaign = current_campaign
|
|
|
|
gift_option = @campaign.campaign_gift_options.find params[:id]
|
|
|
|
json_saved UpdateCampaignGiftOption.update(gift_option, params[:campaign_gift_option]), '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
|
|
|
|
updated_gift_options = UpdateOrder.with_data('campaign_gift_options', params[:data])
|
|
|
|
render json: updated_gift_options
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@campaign = current_campaign
|
|
|
|
|
|
|
|
render_json { DeleteCampaignGiftOption.delete(@campaign, params[:id])}
|
|
|
|
end
|
|
|
|
end
|