diff --git a/app/frontend/src/javascript/controllers/events.js.erb b/app/frontend/src/javascript/controllers/events.js.erb
index c08a98530..eceaacc9f 100644
--- a/app/frontend/src/javascript/controllers/events.js.erb
+++ b/app/frontend/src/javascript/controllers/events.js.erb
@@ -644,7 +644,7 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
if (!user.booked) {
return false;
}
- if ($scope.enableChildValidationRequired && user.booked.type === 'Child' && !user.booked.is_valid) {
+ if ($scope.enableChildValidationRequired && user.booked.type === 'Child' && !user.booked.validated_at) {
return false;
}
}
@@ -675,9 +675,10 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
// get the current user's reservations into $scope.reservations
if ($scope.currentUser) {
- getReservations($scope.event.id, 'Event', $scope.currentUser.id);
- getChildren($scope.currentUser.id).then(function (children) {
- updateNbReservePlaces();
+ getReservations($scope.event.id, 'Event', $scope.currentUser.id).then(function (reservations) {
+ getChildren($scope.currentUser.id).then(function (children) {
+ updateNbReservePlaces();
+ });
});
}
@@ -696,7 +697,7 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
* @param user_id {number} the user's id (current or managed)
*/
const getReservations = function (reservable_id, reservable_type, user_id) {
- Reservation.query({
+ return Reservation.query({
reservable_id,
reservable_type,
user_id
@@ -727,6 +728,14 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
}
}
}
+ for (const r of $scope.reservations) {
+ for (const user of r.booking_users_attributes) {
+ const key = user.booked_type === 'User' ? `user_${user.booked_id}` : `child_${user.booked_id}`;
+ if (key === userKey) {
+ return true;
+ }
+ }
+ }
return false;
};
@@ -748,7 +757,7 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
name: child.first_name + ' ' + child.last_name,
id: child.id,
type: 'Child',
- is_valid: child.is_valid,
+ validated_at: child.validated_at,
birthday: child.birthday
});
}
@@ -761,7 +770,10 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
*/
const updateNbReservePlaces = function () {
if ($scope.event.event_type === 'family') {
- const maxPlaces = $scope.children.length + 1;
+ const reservedPlaces = $scope.reservations.reduce((sum, reservation) => {
+ return sum + reservation.booking_users_attributes.length;
+ }, 0);
+ const maxPlaces = $scope.children.length + 1 - reservedPlaces;
if ($scope.event.nb_free_places > maxPlaces) {
$scope.reserve.nbPlaces.normal = __range__(0, maxPlaces, true);
for (let evt_px_cat of Array.from($scope.event.event_price_categories_attributes)) {
@@ -976,11 +988,11 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', '
Reservation.get({ id: invoice.main_object.id }, function (reservation) {
$scope.event.nb_free_places = $scope.event.nb_free_places - reservation.total_booked_seats;
$scope.reservations.push(reservation);
+ resetEventReserve();
+ updateNbReservePlaces();
+ $scope.reserveSuccess = true;
+ $scope.coupon.applied = null;
});
- resetEventReserve();
- updateNbReservePlaces();
- $scope.reserveSuccess = true;
- $scope.coupon.applied = null;
if ($scope.currentUser.role === 'admin') {
return $scope.ctrl.member = null;
}
diff --git a/app/frontend/templates/events/show.html b/app/frontend/templates/events/show.html
index 045e35deb..0f0183e5b 100644
--- a/app/frontend/templates/events/show.html
+++ b/app/frontend/templates/events/show.html
@@ -142,7 +142,7 @@
class="form-control">
-
+
{{ 'app.shared.cart.child_validation_required_alert' }}
diff --git a/app/models/child.rb b/app/models/child.rb
index 3d752ac54..e91ff6b83 100644
--- a/app/models/child.rb
+++ b/app/models/child.rb
@@ -11,7 +11,7 @@ class Child < ApplicationRecord
validates :first_name, presence: true
validates :last_name, presence: true
# validates :email, presence: true, format: { with: Devise.email_regexp }
- validate :validate_age
+ # validate :validate_age
# birthday should less than 18 years ago
def validate_age