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 EventDiscountsController < ApplicationController
|
2020-05-11 18:38:50 +00:00
|
|
|
include Controllers::Event::Current
|
|
|
|
include Controllers::Event::Authorization
|
2019-07-30 21:29:24 +00:00
|
|
|
before_action :authenticate_event_editor!, except: [:index]
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def create
|
2021-01-13 22:59:04 +00:00
|
|
|
render json: { data: {event_discount: current_event.event_discounts.create(event_discount_params[:event_discount]) } }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
render json: QueryEventDiscounts.with_event_ids([current_event.id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2021-01-13 22:59:04 +00:00
|
|
|
|
|
|
|
current_event_discount.update event_discount_params[:event_discount]
|
|
|
|
render json: { status: 200, data: current_event_discount }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2021-01-13 22:59:04 +00:00
|
|
|
current_event_discount.destroy
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
2019-08-06 14:05:24 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-01-13 22:59:04 +00:00
|
|
|
def current_event_discount
|
|
|
|
current_event.event_discounts.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2019-08-06 14:05:24 +00:00
|
|
|
def event_discount_params
|
2021-01-13 22:59:04 +00:00
|
|
|
params.required(:event_discount).permit(:code, :name, :percent)
|
2019-08-06 14:05:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|