Class: Api::Dashboard::V2::ReservationsFilter

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

Overview

Responsible to filter reservations data dashboard

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ReservationHistory

#history, #history_result

Constructor Details

#initialize(restaurants, collections = nil) ⇒ ReservationsFilter

Returns a new instance of ReservationsFilter.

Parameters:

  • collections (Reservation) (defaults to: nil)

    Reservation relations



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

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

Instance Attribute Details

#collectionsObject

Returns the value of attribute collections.



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

def collections
  @collections
end

#error_messageObject

Returns the value of attribute error_message.



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

def error_message
  @error_message
end

Instance Method Details

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



27
28
29
# File 'app/filters/api/dashboard/v2/reservations_filter.rb', line 27

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

#build_collectionsObject

get desired reservations from database



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/filters/api/dashboard/v2/reservations_filter.rb', line 32

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_service_type
    _filter_by_specific_package
    _filter_package_type
    _filter_by_package_id
    _filter_by_add_on_id
    _filter_by_payment_status
    _filter_by_booking_list
  end
  _order_by
  collections
end

#filter(filter_par) ⇒ Object



16
17
18
19
20
# File 'app/filters/api/dashboard/v2/reservations_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
25
# File 'app/filters/api/dashboard/v2/reservations_filter.rb', line 22

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