Class: Api::Partner::RestaurantPackagesFilter

Inherits:
Object
  • Object
show all
Defined in:
app/filters/api/partner/restaurant_packages_filter.rb

Overview

Responsible to filter reservation packages data dashboard

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(restaurants) ⇒ RestaurantPackagesFilter

Returns a new instance of RestaurantPackagesFilter.

Parameters:

  • restaurants (Restaurant)

    Restaurant relations



9
10
11
12
13
14
# File 'app/filters/api/partner/restaurant_packages_filter.rb', line 9

def initialize(restaurants)
  @restaurants = restaurants
  self.collections = default_collections
  @time_zone = Time.now.in_time_zone(@restaurants.first.time_zone).strftime('%Z')
  @config = {}
end

Instance Attribute Details

#collectionsObject

Returns the value of attribute collections.



6
7
8
# File 'app/filters/api/partner/restaurant_packages_filter.rb', line 6

def collections
  @collections
end

#error_messageObject

Returns the value of attribute error_message.



6
7
8
# File 'app/filters/api/partner/restaurant_packages_filter.rb', line 6

def error_message
  @error_message
end

#time_zoneObject

Returns the value of attribute time_zone.



6
7
8
# File 'app/filters/api/partner/restaurant_packages_filter.rb', line 6

def time_zone
  @time_zone
end

Instance Method Details

#build_collectionsObject

Get desired reservations from database



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/filters/api/partner/restaurant_packages_filter.rb', line 27

def build_collections
  if filter_params
    _filter_by_package_id
    _filter_by_package_name
    _filter_by_package_type
    _filter_by_package_status
    _filter_by_booking_duration
    _filter_by_created_date_range
    _filter_by_updated_date_range
    _filter_by_created_date
    _filter_by_updated_date
  end
  _order_by
  collections
end

#filter(filter_par) ⇒ Object



16
17
18
19
20
# File 'app/filters/api/partner/restaurant_packages_filter.rb', line 16

def filter(filter_par)
  return if filter_par.blank?

  config[:filter] = filter_par
end

#order_by(order) ⇒ Object



22
23
24
# File 'app/filters/api/partner/restaurant_packages_filter.rb', line 22

def order_by(order)
  config[:order_by] = order
end

#to_collectionsObject



43
44
45
# File 'app/filters/api/partner/restaurant_packages_filter.rb', line 43

def to_collections
  build_collections.order(created_at: :desc)
end