Class: Ecom::Core::FilterService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ecom/core/filter_service.rb

Instance Method Summary collapse

Instance Method Details

#get_filtered_data(type, filters) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/services/ecom/core/filter_service.rb', line 4

def get_filtered_data(type, filters)
  positive = {}
  negative = {}
  obj = type.constantize
  filters.each { |f|
    if f[:cond] == 'P'
      positive[f[:key]] = f[:value]
    else
      negative[f[:key]] = f[:value]
    end
  }
  obj.where(positive).where.not(negative)
end