Class: Api::Dashboard::ReservationsFilter

Inherits:
Object
  • Object
show all
Defined in:
app/filters/api/dashboard/reservations_filter.rb

Overview

Responsible to filter reservations data dashboard

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collections = nil) ⇒ ReservationsFilter

Returns a new instance of ReservationsFilter.

Parameters:

  • collections (Reservation) (defaults to: nil)

    Reservation relations



9
10
11
12
# File 'app/filters/api/dashboard/reservations_filter.rb', line 9

def initialize(collections = nil)
  self.collections = collections unless collections.nil?
  @config = {}
end

Instance Attribute Details

#collectionsObject

Returns the value of attribute collections.



6
7
8
# File 'app/filters/api/dashboard/reservations_filter.rb', line 6

def collections
  @collections
end

#error_messageObject

Returns the value of attribute error_message.



6
7
8
# File 'app/filters/api/dashboard/reservations_filter.rb', line 6

def error_message
  @error_message
end

Instance Method Details

#as_json(collections, options = {}) ⇒ Object



25
26
27
# File 'app/filters/api/dashboard/reservations_filter.rb', line 25

def as_json(collections, options = {})
  Api::Dashboard::ReservationSerializer.new(collections, options).as_json
end

#build_collectionsObject

get desired reservations from database



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/filters/api/dashboard/reservations_filter.rb', line 30

def build_collections
  if filter_params
    _filter_by_status
    _filter_by_name
    _filter_by_email
    _filter_by_phone
    _filter_by_booking_id
    _filter_by_date
    _filter_by_date_range
    _filter_by_start_time
    _filter_by_party_size
    _filter_by_adult
    _filter_by_kids
    _filter_by_today
    _filter_by_upcoming
    _filter_by_service_type
  end
  _order_by
  collections
end

#filter(filter_par) ⇒ Object



14
15
16
17
18
# File 'app/filters/api/dashboard/reservations_filter.rb', line 14

def filter(filter_par)
  return unless filter_par.present?

  config[:filter] = filter_par
end

#order_by(order) ⇒ Object



20
21
22
23
# File 'app/filters/api/dashboard/reservations_filter.rb', line 20

def order_by(order)
  order = order.presence || ['id']
  config[:order_by] = order
end