mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 12:45:46 +08:00
init project
This commit is contained in:
32
app/queries/admins/department_query.rb
Normal file
32
app/queries/admins/department_query.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
class Admins::DepartmentQuery < ApplicationQuery
|
||||
include CustomSortable
|
||||
|
||||
attr_reader :params
|
||||
|
||||
sort_columns :created_at, default_by: :created_at, default_direction: :desc
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
departments = Department.where(is_auth: true).without_deleted
|
||||
|
||||
keyword = params[:keyword].to_s.strip
|
||||
if keyword.present?
|
||||
departments = departments.joins(:school)
|
||||
.where('schools.name LIKE :keyword OR departments.name LIKE :keyword', keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
if params[:with_member].to_s == 'true'
|
||||
subquery = DepartmentMember.where('department_id = departments.id').select('1 AS one').to_sql
|
||||
departments = departments.where("EXISTS(#{subquery})")
|
||||
end
|
||||
|
||||
if params[:with_identifier].to_s == 'true'
|
||||
departments = departments.where.not(identifier: nil).where.not(identifier: '')
|
||||
end
|
||||
|
||||
custom_sort(departments, params[:sort_by], params[:sort_direction])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user