Class: PropertySerializer

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

Instance Method Summary collapse

Instance Method Details

#additional_rulesObject



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

#amenitiesObject



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_datesObject



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.message}")
  []
end

#cancellation_policyObject



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_imageObject



36
37
38
# File 'app/serializers/property_serializer.rb', line 36

def cover_image
  object.cover_image_url
end

#featuresObject



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_rulesObject



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_propertyObject



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

def is_shared_property
  object.shared_property
end

#place_imagesObject



40
41
42
# File 'app/serializers/property_serializer.rb', line 40

def place_images
  object.place_images.attached? ? object.place_images_urls : []
end

#property_taxesObject



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