Class: ResourceUsage
- Inherits:
-
Object
- Object
- ResourceUsage
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/resource_usage.rb
Overview
Resources usage (reservation) collection
Schema information
Collection name: resource : Available resources
_id BSON::ObjectId _id
created_at Time Created at time
updated_at Time Last updated at time
time_from DateTime Reservation start time
time_to DateTime Reservation end time
description String Description of the reservation
resource_id BSON::ObjectId Resource id
dc_user_id BSON::ObjectId Reservation was created by
active Boolean Resource is active
Instance Method Summary collapse
-
#free_time_validations ⇒ Object
Validates if resource is available in specified time window.
Instance Method Details
#free_time_validations ⇒ Object
Validates if resource is available in specified time window.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/resource_usage.rb', line 66 def free_time_validations errors.add(:time_from, "should be less then end time!") if time_from >= time_to errors.add(:time_from, "is less then current time!") if time_from <= Time.now if ResourceUsage.where(resource_id: resource_id).and({"$or" => [ {"$and" => [ {:time_from.lt => time_from}, {:time_to.gt => time_from} ] }, {"$and" => [ {:time_from.lt => time_to}, {:time_to.gt => time_to} ] }, {"$and" => [ {:time_from.gte => time_from}, {:time_to.lte => time_to} ] } ] }).exists? errors.add(:time_from, "Resource already taken!") end end |