Class: Api::Vendor::V1::Klook::BookingSerializer

Inherits:
BaseSerializer show all
Includes:
Concerns::SerializerUtils
Defined in:
app/serializers/api/vendor/v1/klook/booking_serializer.rb

Instance Method Summary collapse

Methods inherited from BaseSerializer

enable_caching

Constructor Details

#initialize(reservation_or_reservations, options = {}) ⇒ BookingSerializer

Returns a new instance of BookingSerializer.



5
6
7
8
9
10
# File 'app/serializers/api/vendor/v1/klook/booking_serializer.rb', line 5

def initialize(reservation_or_reservations, options = {})
  super()
  # Accepts either a single reservation object or an array of reservations.
  @reservations = reservation_or_reservations
  @options = options
end

Instance Method Details

#as_jsonObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/serializers/api/vendor/v1/klook/booking_serializer.rb', line 12

def as_json(*)
  if @options[:route] == 'bookings-list'
    @reservations.map { |reservation| serialize_booking(reservation.decorate) }
  else
    if @options[:route] == 'booking-detail'
      return {} if @reservations.blank?

      reservation = @reservations.first
    else
      reservation = @reservations
    end
    serialize_booking(reservation.decorate)
  end
end