Class: BookingSerializer

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

Instance Method Summary collapse

Instance Method Details

#calculate_city_feeObject



55
56
57
# File 'app/serializers/booking_serializer.rb', line 55

def calculate_city_fee
  object.property.city_fee
end

#calculate_cleaning_feeObject



51
52
53
# File 'app/serializers/booking_serializer.rb', line 51

def calculate_cleaning_fee
  object.property.cleaning_fee
end

#calculate_totalsObject



27
28
29
# File 'app/serializers/booking_serializer.rb', line 27

def calculate_totals
  object.calculate_totals
end

#check_in_dateObject



11
12
13
# File 'app/serializers/booking_serializer.rb', line 11

def check_in_date
  object.check_in_date.strftime("%B %d, %Y")
end

#check_out_dateObject



15
16
17
# File 'app/serializers/booking_serializer.rb', line 15

def check_out_date
  object.check_out_date.strftime("%B %d, %Y")
end

#completed_atObject



19
20
21
# File 'app/serializers/booking_serializer.rb', line 19

def completed_at
  object.completed_at
end

#extra_guest_amountObject



39
40
41
# File 'app/serializers/booking_serializer.rb', line 39

def extra_guest_amount
  object.extra_guest_amount
end

#invoice_totalObject



47
48
49
# File 'app/serializers/booking_serializer.rb', line 47

def invoice_total
  object.invoice&.total
end

#last_five_messagesObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/serializers/booking_serializer.rb', line 59

def last_five_messages
  return nil unless object&.chat
  return nil unless object&.chat&.messages.any?
  messages = if scope&.dig(:current_user)&.stay_user?
    object.chat.messages.where(event_for: [ "student", "both" ])
  elsif scope&.dig(:current_user)&.stay_host?
    object.chat.messages.where(event_for: [ "host", "both" ])
  else
    object.chat.messages
  end
  last_five = messages.last(5)
  ActiveModelSerializers::SerializableResource.new(last_five, each_serializer: MessageSerializer)
end

#property_userObject



43
44
45
# File 'app/serializers/booking_serializer.rb', line 43

def property_user
  object.property.user.present? ? UserListingSerializer.new(object.property.user) : nil
end

#room_countObject



31
32
33
# File 'app/serializers/booking_serializer.rb', line 31

def room_count
  object.rooms.count
end

#tax_totalObject



35
36
37
# File 'app/serializers/booking_serializer.rb', line 35

def tax_total
  object.calculate_tax_total
end

#totalObject



23
24
25
# File 'app/serializers/booking_serializer.rb', line 23

def total
  object.total_amount
end