Class: Api::Partner::ReservationsFilter

Inherits:
Object
  • Object
show all
Includes:
ElasticAPM::SpanHelpers, ReservationHistory
Defined in:
app/filters/api/partner/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(restaurant, collections = nil) ⇒ ReservationsFilter

Returns a new instance of ReservationsFilter.

Parameters:

  • collections (Reservation) (defaults to: nil)

    Reservation relations



11
12
13
14
15
# File 'app/filters/api/partner/reservations_filter.rb', line 11

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

Instance Attribute Details

#collectionsObject

Returns the value of attribute collections.



8
9
10
# File 'app/filters/api/partner/reservations_filter.rb', line 8

def collections
  @collections
end

#error_messageObject

Returns the value of attribute error_message.



8
9
10
# File 'app/filters/api/partner/reservations_filter.rb', line 8

def error_message
  @error_message
end

Instance Method Details

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



29
30
31
32
# File 'app/filters/api/partner/reservations_filter.rb', line 29

def as_json(collections, options = {})
  options[:params][:loyalty_levels] = LoyaltyLevel.fetch_data
  Api::Partner::ReservationSerializer.new(collections, options).as_json
end

#build_collectionsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/filters/api/partner/reservations_filter.rb', line 35

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_upcoming
    _filter_by_service_type
    _filter_by_specific_package
    _filter_by_specific_package_id
    _filter_package_type
    _filter_by_payment_status
    _filter_by_booking_list
  end
  _order_by
  collections
end

#filter(filter_par) ⇒ Object



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

def filter(filter_par)
  return if filter_par.blank?

  config[:filter] = filter_par
end

#order_by(order) ⇒ Object



23
24
25
26
27
# File 'app/filters/api/partner/reservations_filter.rb', line 23

def order_by(order)
  # Handle empty arrays and arrays with empty strings
  order = order.presence&.reject(&:blank?) || ['id']
  config[:order_by] = order
end