2016-06-23 11:23:18 +00:00
|
|
|
class Bus
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
field :bus_route, localize: true
|
|
|
|
field :departure_time, type: DateTime
|
|
|
|
field :reservation_end_time, type: DateTime
|
|
|
|
field :remark, localize: true
|
|
|
|
field :capacity, type: Integer
|
|
|
|
field :created_by
|
|
|
|
|
|
|
|
has_many :bookings
|
|
|
|
|
|
|
|
|
|
|
|
def can_reserve?
|
2016-08-10 10:32:45 +00:00
|
|
|
self.reservation_end_time > Time.now && self.bookings.count <= self.capacity
|
2016-06-23 11:23:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def posted_by
|
|
|
|
User.find(self.created_by).name rescue ""
|
|
|
|
end
|
|
|
|
|
2016-08-10 10:32:45 +00:00
|
|
|
def already_reserved?(user)
|
|
|
|
self.bookings.where(:user_id => user.id.to_s).count == 1
|
|
|
|
end
|
|
|
|
|
2016-06-23 11:23:18 +00:00
|
|
|
end
|