2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
2018-03-25 17:30:42 +00:00
|
|
|
class CampaignGiftOptionsController < ApplicationController
|
2020-05-11 18:38:50 +00:00
|
|
|
include Controllers::Campaign::Current
|
|
|
|
include Controllers::Campaign::Authorization
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
before_action :authenticate_campaign_editor!, only: %i[create destroy update update_order]
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def index
|
|
|
|
@gift_options = current_campaign.campaign_gift_options.order('"order", amount_recurring, amount_one_time')
|
|
|
|
render json: { data: @gift_options }
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def show
|
|
|
|
render json: { data: current_campaign.campaign_gift_options.find(params[:id]) }
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def create
|
2021-01-15 23:10:37 +00:00
|
|
|
json_saved CreateCampaignGiftOption.create(current_campaign, campaign_gift_option_params),
|
2019-07-30 21:29:24 +00:00
|
|
|
'Gift option successfully created!'
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def update
|
2021-01-15 23:10:37 +00:00
|
|
|
json_saved UpdateCampaignGiftOption.update(current_campaign_gift_option, campaign_gift_option_params), 'Successfully updated'
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def destroy
|
2021-01-15 23:10:37 +00:00
|
|
|
render_json { DeleteCampaignGiftOption.delete(current_campaign_gift_option) }
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2019-08-06 12:36:31 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def campaign_gift_option_params
|
|
|
|
params.require(:campaign_gift_option).permit(:amount_one_time, :amount_recurring, :amount_dollars, :description, :name, :campaign, :quantity, :to_ship, :order, :hide_contributions)
|
|
|
|
end
|
2021-01-15 23:10:37 +00:00
|
|
|
|
|
|
|
def current_campaign_gift_option
|
|
|
|
campaign.campaign_gift_options.find(params[:id])
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|