Class: Api::Partner::TicketFilter

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

Overview

Responsible to filter reservations data dashboard

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collections = nil) ⇒ TicketFilter

Returns a new instance of TicketFilter.

Parameters:

  • collections (Reservation) (defaults to: nil)

    Reservation relations



9
10
11
12
# File 'app/filters/api/partner/ticket_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/partner/ticket_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/ticket_filter.rb', line 6

def error_message
  @error_message
end

Instance Method Details

#build_collectionsObject

get desired reservations from database



25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/filters/api/partner/ticket_filter.rb', line 25

def build_collections
  if filter_params
    _filter_by_voucher_number
    _filter_by_voucher_detail
    _filter_by_guest_detail
    _filter_by_redeemed_time
    _filter_by_redeemed_date_range
    _filter_by_redeemed_date
  end
  _order_by
  collections.group(:id)
end

#filter(filter_par) ⇒ Object



14
15
16
17
18
# File 'app/filters/api/partner/ticket_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
# File 'app/filters/api/partner/ticket_filter.rb', line 20

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

#to_collectionsObject



38
39
40
# File 'app/filters/api/partner/ticket_filter.rb', line 38

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