You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 24, 2020. It is now read-only.
# These validation methods each run several validations within them
4
+
# for the sake of speed and query-saving. They are separated in 3 methods
5
+
# so that the cart doesn't have to validate items when only the dates are
6
+
# changed and vice versa. Each method returns an array of error messages
7
+
#
8
+
#
9
+
# Validate Dates (when dates are changed)
10
+
# ## start, end not on a blackout date
11
+
# ## user has no overdue (reserver is included in the date form)
12
+
#
13
+
# Validate Items (when items are added/removed)
14
+
# ## user doesn't have too many of each equipment model
15
+
# ## or each category
16
+
#
17
+
# Validate Dates and Items
18
+
# ## items are all available for the date range
19
+
# ## the duration of the date range is short enough
20
+
# ## none of the items should be renewed instead of re-reserved
21
+
#
22
+
# Validate All
23
+
# ## just runs everything
24
+
25
+
26
+
defvalidate_dates
27
+
errors=[]
28
+
29
+
# blackouts
30
+
errors << "A reservation cannot start on #{self.start_date.to_date.strftime('%m/%d')}"ifBlackout.hard.for_date(self.start_date).count > 0
31
+
errors << "A reservation cannot end on #{self.due_date.to_date.strftime('%m/%d')}"ifBlackout.hard.for_date(self.due_date).count > 0
32
+
33
+
# no overdue reservations
34
+
errors << "This user has overdue reservations that prevent him/her from creating new ones"ifReservation.for_reserver(self.reserver_id).overdue.count > 0
# the array of reservations passed in (use with cart.cart_reservations)
101
-
# Returns an array of error messages or [] if reservations are all valid
102
-
defself.validate_set(user,res_array=[])
103
-
errors=[]
104
-
#User reservation validations
105
-
errors << user.name + " has overdue reservations that prevent new ones from being created. "unlessuser.reservations.overdue.empty?
106
-
107
-
res_array.eachdo |res|
108
-
errors << "Reservation cannot be made in the past. "unlessres.not_in_past?
109
-
errors << "Reservation start date must be before due date. "unlessres.start_date_before_due_date?
110
-
errors << "Reservation must be for a piece of equipment. "unlessres.not_empty?
111
-
errors << "#{res.equipment_object.name} must be of type #{res.equipment_model.name}. "unlessres.matched_object_and_model?
112
-
errors << "#{res.equipment_model.name} should be renewed instead of re-checked out. "unlessres.not_renewable?
113
-
errors << "#{res.equipment_model.name} cannot be reserved for more than #{res.equipment_model.category.maximum_checkout_length.to_s} days at a time. "unlessres.duration_allowed?
114
-
errors << "#{res.equipment_model.name} is not available for the full time period requested. "unlessres.available?(res_array)
115
-
errors << "A reservation cannot start on #{res.start_date.strftime('%m/%d')} because equipment cannot be picked up on that date. "unlessres.start_date_is_not_blackout?
116
-
errors << "A reservation cannot end on #{res.due_date.strftime('%m/%d')} because equipment cannot be returned on that date. "unlessres.due_date_is_not_blackout?
117
-
errors << "Cannot reserve more than #{res.equipment_model.maximum_per_user.to_s}#{res.equipment_model.name.pluralize}. "unlessres.quantity_eq_model_allowed?res_array
118
-
errors << "Cannot reserve more than #{res.equipment_model.category.maximum_per_user.to_s}#{res.equipment_model.category.name.pluralize}. "unlessres.quantity_cat_allowed?res_array
0 commit comments