Class: RoomSerializer

Inherits:
ActiveModel::Serializer
  • Object
show all
Defined in:
app/serializers/room_serializer.rb

Instance Method Summary collapse

Instance Method Details

#amenitiesObject



14
15
16
# File 'app/serializers/room_serializer.rb', line 14

def amenities
  ActiveModelSerializers::SerializableResource.new(object.amenities.distinct, each_serializer: AmenitySerializer)
end

#bed_typeObject



6
7
8
# File 'app/serializers/room_serializer.rb', line 6

def bed_type
  object.bed_type && BedTypeSerializer.new(object.bed_type)
end

#booked_datesObject



26
27
28
29
30
31
32
33
34
35
# File 'app/serializers/room_serializer.rb', line 26

def booked_dates
  return [] unless object.property&.shared_property

  bookings = Stay::Booking.joins(line_items: :property)
                          .where(line_items: { room_id: object.id })
  bookings.exists? ? bookings.pluck(:check_in_date, :check_out_date).uniq : []
rescue StandardError => e
  Rails.logger.error("Error fetching bookings for room #{object.id}: #{e.message}")
  []
end

#featuresObject



18
19
20
# File 'app/serializers/room_serializer.rb', line 18

def features
  ActiveModelSerializers::SerializableResource.new(object.features.distinct, each_serializer: FeatureSerializer)
end

#room_imagesObject



22
23
24
# File 'app/serializers/room_serializer.rb', line 22

def room_images
  object.room_images.map(&:url).compact
end

#room_typeObject



10
11
12
# File 'app/serializers/room_serializer.rb', line 10

def room_type
  object.room_type && RoomTypeSerializer.new(object.room_type)
end