Class: RoomSerializer
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- RoomSerializer
- Defined in:
- app/serializers/room_serializer.rb
Instance Method Summary collapse
- #amenities ⇒ Object
- #bed_type ⇒ Object
- #booked_dates ⇒ Object
- #features ⇒ Object
- #room_images ⇒ Object
- #room_type ⇒ Object
Instance Method Details
#amenities ⇒ Object
14 15 16 |
# File 'app/serializers/room_serializer.rb', line 14 def amenities ActiveModelSerializers::SerializableResource.new(object.amenities.distinct, each_serializer: AmenitySerializer) end |
#bed_type ⇒ Object
6 7 8 |
# File 'app/serializers/room_serializer.rb', line 6 def bed_type object.bed_type && BedTypeSerializer.new(object.bed_type) end |
#booked_dates ⇒ Object
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.}") [] end |
#features ⇒ Object
18 19 20 |
# File 'app/serializers/room_serializer.rb', line 18 def features ActiveModelSerializers::SerializableResource.new(object.features.distinct, each_serializer: FeatureSerializer) end |
#room_images ⇒ Object
22 23 24 |
# File 'app/serializers/room_serializer.rb', line 22 def room_images object.room_images.map(&:url).compact end |
#room_type ⇒ Object
10 11 12 |
# File 'app/serializers/room_serializer.rb', line 10 def room_type object.room_type && RoomTypeSerializer.new(object.room_type) end |