class Admins::OrganizationQuery < ApplicationQuery
    include CustomSortable
    attr_reader :params
    sort_columns :created_on, :last_login_on, :experience, :grade, default_by: :created_on, default_direction: :desc

    def initialize(params)
        @params = params
    end

    def call
        orgs = Organization.all

        orgs = orgs.where(enabling_cla: params[:enabling_cla]) if params[:enabling_cla].present?
        # 关键字检索
        keyword = params[:keyword].to_s.strip.presence
        if keyword
            sql = 'nickname LIKE :keyword OR login LIKE :keyword'
            orgs = orgs.where(sql, keyword: "%#{keyword}%")
        end
    
        custom_sort(orgs, params[:sort_by], params[:sort_direction])
    end
end