2021-06-29 11:14:36 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for resources of type StatisticProfilePrepaidPack
|
2021-06-29 15:59:57 +02:00
|
|
|
class API::UserPacksController < API::ApiController
|
2021-06-29 11:14:36 +02:00
|
|
|
before_action :authenticate_user!
|
|
|
|
|
|
|
|
def index
|
|
|
|
@user_packs = PrepaidPackService.user_packs(user, item)
|
2023-03-09 13:23:42 +01:00
|
|
|
|
|
|
|
@history = params[:history] == 'true'
|
|
|
|
@user_packs = @user_packs.includes(:prepaid_pack_reservations) if @history
|
2021-06-29 11:14:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def user
|
|
|
|
return User.find(params[:user_id]) if current_user.privileged?
|
|
|
|
|
|
|
|
current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def item
|
2023-01-20 13:57:36 +01:00
|
|
|
return nil if params[:priceable_type].nil?
|
|
|
|
|
2021-06-29 11:14:36 +02:00
|
|
|
params[:priceable_type].classify.constantize.find(params[:priceable_id])
|
|
|
|
end
|
|
|
|
end
|