Class: PropertySerializer
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- PropertySerializer
- Defined in:
- app/serializers/property_serializer.rb
Instance Method Summary collapse
- #additional_rules ⇒ Object
- #amenities ⇒ Object
- #booked_dates ⇒ Object
- #cancellation_policy ⇒ Object
- #cover_image ⇒ Object
- #features ⇒ Object
- #house_rules ⇒ Object
- #is_shared_property ⇒ Object
- #place_images ⇒ Object
- #property_taxes ⇒ Object
Instance Method Details
#additional_rules ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'app/serializers/property_serializer.rb', line 44 def additional_rules object.additional_rules.map do |rule| { id: rule.id, name: rule.name } end end |
#amenities ⇒ Object
14 15 16 |
# File 'app/serializers/property_serializer.rb', line 14 def amenities ActiveModelSerializers::SerializableResource.new(object.property_type_amenities, each_serializer: AmenitySerializer) end |
#booked_dates ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'app/serializers/property_serializer.rb', line 69 def booked_dates return [] if object.shared_property bookings = Stay::Booking.joins(:property).where(stay_properties: { 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 |
#cancellation_policy ⇒ Object
64 65 66 67 |
# File 'app/serializers/property_serializer.rb', line 64 def cancellation_policy return nil unless object.cancellation_policy.present? CancellationPolicySerializer.new(object.cancellation_policy) end |
#cover_image ⇒ Object
36 37 38 |
# File 'app/serializers/property_serializer.rb', line 36 def cover_image object.cover_image_url end |
#features ⇒ Object
18 19 20 |
# File 'app/serializers/property_serializer.rb', line 18 def features ActiveModelSerializers::SerializableResource.new(object.property_type_features, each_serializer: FeatureSerializer) end |
#house_rules ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/serializers/property_serializer.rb', line 26 def house_rules object.property_house_rules.map do |rule| { id: rule.house_rule.id, name: rule.house_rule.name, value: rule.value } end end |
#is_shared_property ⇒ Object
22 23 24 |
# File 'app/serializers/property_serializer.rb', line 22 def is_shared_property object.shared_property end |
#place_images ⇒ Object
40 41 42 |
# File 'app/serializers/property_serializer.rb', line 40 def place_images object.place_images.attached? ? object.place_images_urls : [] end |
#property_taxes ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'app/serializers/property_serializer.rb', line 53 def property_taxes object.property_taxes.uniq { |property_tax| property_tax.tax_id }.map do |property_tax| { id: property_tax.id, name: property_tax.tax.name, tax_id: property_tax.tax.id, value: property_tax.value } end end |