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 TicketLevelsController < ApplicationController
|
2020-05-11 18:38:50 +00:00
|
|
|
include Controllers::Event::Current
|
|
|
|
include Controllers::Event::Authorization
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
before_action :authenticate_event_editor!, except: %i[index show]
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def index
|
2018-03-25 17:30:42 +00:00
|
|
|
ev_id = current_event.id
|
2019-07-30 21:29:24 +00:00
|
|
|
render json: { data: QueryTicketLevels.with_event_id(ev_id, current_role?(:event_editor, ev_id) || current_role?(:super_admin) || current_role?(:nonprofit_admin, current_event.nonprofit_id)) }
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def show
|
|
|
|
render json: current_ticket_level
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def create
|
2019-08-06 14:08:15 +00:00
|
|
|
ticket_level = current_event.ticket_levels.create ticket_level_params
|
2019-07-30 21:29:24 +00:00
|
|
|
json_saved ticket_level, 'Ticket level created!'
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def update
|
2020-05-20 21:03:16 +00:00
|
|
|
current_ticket_level.update ticket_level_params
|
2019-07-30 21:29:24 +00:00
|
|
|
json_saved current_ticket_level, 'Ticket level updated'
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
# put /nonprofits/:nonprofit_id/events/:event_id/ticket_levels/update_order
|
|
|
|
# Pass in {data: [{id: 1, order: 1}]}
|
|
|
|
def update_order
|
|
|
|
updated_ticket_levels = UpdateOrder.with_data('ticket_levels', params[:data])
|
|
|
|
render json: updated_ticket_levels
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2019-07-30 21:29:24 +00:00
|
|
|
current_ticket_level.destroy
|
|
|
|
render json: {}
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
private
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def current_ticket_level
|
|
|
|
@ticket_level ||= current_event.ticket_levels.find params[:id]
|
|
|
|
end
|
2019-08-06 14:08:15 +00:00
|
|
|
|
|
|
|
def ticket_level_params
|
|
|
|
params.require(:ticket_level).permit(:amount, :amount_dollars, :name, :description, :quantity, :deleted, :event_id, :admin_only, :limit, :order)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|