Class: Collavre::Creatives::Filters::AssigneeFilter

Inherits:
BaseFilter
  • Object
show all
Defined in:
app/services/collavre/creatives/filters/assignee_filter.rb

Instance Method Summary collapse

Methods inherited from BaseFilter

#initialize

Constructor Details

This class inherits a constructor from Collavre::Creatives::Filters::BaseFilter

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'app/services/collavre/creatives/filters/assignee_filter.rb', line 5

def active?
  params[:assignee_id].present? || params[:unassigned].present?
end

#matchObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/collavre/creatives/filters/assignee_filter.rb', line 9

def match
  if params[:unassigned] == "true"
    # owner가 없는 Label을 가진 creative 또는 태그가 없는 creative
    with_null_owner = scope.left_joins(tags: :label)
                           .where(labels: { owner_id: nil })
                           .pluck(:id)
    without_tags = scope.left_joins(:tags)
                        .where(tags: { id: nil })
                        .pluck(:id)
    (with_null_owner + without_tags).uniq
  else
    assignee_ids = Array(params[:assignee_id]).map(&:to_i)
    scope.joins(tags: :label)
         .where(labels: { owner_id: assignee_ids })
         .distinct
         .pluck(:id)
  end
end