You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1022 B
34 lines
1022 B
class Admins::HackQuery < ApplicationQuery
|
|
include CustomSortable
|
|
|
|
attr_reader :params
|
|
|
|
sort_columns :id, :created_at, default_by: :created_at, default_direction: :desc, default_table: "item_banks"
|
|
|
|
def initialize(params)
|
|
@params = params
|
|
end
|
|
|
|
def call
|
|
item_banks = ItemBank.PROGRAM
|
|
|
|
if params[:sub].present?
|
|
item_banks = item_banks.joins(:sub_discipline).where("sub_disciplines.name like ?", "%#{params[:sub]}%")
|
|
end
|
|
if params[:public].present?
|
|
item_banks = item_banks.joins(
|
|
"JOIN hacks ON hacks.id = item_banks.container_id AND item_banks.container_type = 'Hack' AND status = #{params[:public] == "true" ? 1 : 0}"
|
|
)
|
|
end
|
|
if params[:name].present?
|
|
item_banks = item_banks.where('item_banks.name like ?', "%#{params[:name]}%")
|
|
end
|
|
|
|
if params[:user].present?
|
|
item_banks = item_banks.joins(:user).where('lastname like ?', "%#{params[:user]}%")
|
|
end
|
|
|
|
custom_sort(item_banks, params[:sort_by], params[:sort_direction])
|
|
|
|
end
|
|
end |