1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

(bug) fix slot reservation is considered full

This commit is contained in:
Sylvain 2022-07-19 15:40:28 +02:00
parent fa45917d6f
commit 06ee1acea5
9 changed files with 17 additions and 15 deletions

View File

@ -1,3 +1,3 @@
#web: bundle exec rails server puma -p $PORT
web: bundle exec rails server puma -p $PORT
worker: bundle exec sidekiq -C ./config/sidekiq.yml
webpack: bin/webpacker-dev-server

View File

@ -55,7 +55,7 @@ class API::PayzenController < API::PaymentsController
def check_cart
cart = shopping_cart
render json: { error: 'unable to pay' }, status: :unprocessable_entity and return unless cart.valid?
render json: { error: 'invalid shopping cart' }, status: :unprocessable_entity and return unless cart.valid?
render json: { cart: 'ok' }, status: :ok
end

View File

@ -19,9 +19,8 @@ class API::StripeController < API::PaymentsController
res = nil # json of the API answer
cart = shopping_cart
unless cart.valid?
render json: { error: 'unable to pay' }, status: :unprocessable_entity and return
end
render json: { error: 'invalid shopping cart' }, status: :unprocessable_entity and return unless cart.valid?
begin
amount = debit_amount(cart) # will contains the amount and the details of each invoice lines
if params[:payment_method_id].present?

View File

@ -697,7 +697,7 @@ Application.Controllers.controller('ReserveMachineController', ['$scope', '$tran
return;
}
$scope.selectedEvent = event;
return $scope.selectionTime = new Date();
$scope.selectionTime = new Date();
};
/**

View File

@ -517,8 +517,8 @@ Application.Directives.directive('cart', ['$rootScope', '$uibModal', 'dialogs',
$scope.slot.group_ids = $scope.slot.plansGrouped.map(function (g) { return g.id; });
}
if (!$scope.slot.is_reserved && !$scope.events.modifiable && !$scope.slot.is_completed) {
// slot is not reserved and we are not currently modifying a slot
if (!$scope.slot.is_completed && !$scope.events.modifiable) {
// slot is not fully reserved, and we are not currently modifying a slot
// -> can be added to cart or removed if already present
const index = _.findIndex($scope.events.reserved, (e) => e._id === $scope.slot._id);
if (index === -1) {
@ -538,9 +538,9 @@ Application.Directives.directive('cart', ['$rootScope', '$uibModal', 'dialogs',
resetCartState();
// finally, we update the prices
return updateCartPrice();
} else if (!$scope.slot.is_reserved && !$scope.slot.is_completed && $scope.events.modifiable) {
// slot is not reserved but we are currently modifying a slot
// -> we request the calender to change the rendering
} else if (!$scope.slot.is_completed && $scope.events.modifiable) {
// slot is not fully reserved, but we are currently modifying a slot
// -> we request the calendar to change the rendering
if (typeof $scope.onSlotModifyUnselect === 'function') {
// if the callback return false, cancel the selection for the current modification
const res = $scope.onSlotModifyUnselect();

View File

@ -24,7 +24,7 @@ class Availabilities::StatusService
user_slots_reservations = slots_reservations.where('reservations.statistic_profile_id': statistic_profile_id)
slot.is_reserved = !user_slots_reservations.empty?
slot.is_reserved = !slots_reservations.empty?
slot.title = slot_title(slots_reservations, user_slots_reservations, reservables)
slot.can_modify = true if %w[admin manager].include?(@current_user_role) || !user_slots_reservations.empty?
slot.current_user_slots_reservations_ids = user_slots_reservations.map(&:id)
@ -46,7 +46,7 @@ class Availabilities::StatusService
user_slots_reservations = slots_reservations.where('reservations.statistic_profile_id': user&.statistic_profile&.id)
availability.is_reserved = !user_slots_reservations.empty?
availability.is_reserved = !slots_reservations.empty?
availability.current_user_slots_reservations_ids = user_slots_reservations.map(&:id)
availability
end
@ -62,7 +62,7 @@ class Availabilities::StatusService
.map(&:user)
.map { |u| u&.profile&.full_name || I18n.t('availabilities.deleted_user') }
.join(', ')
"#{name} - #{@show_name ? user_names : I18n.t('availabilities.not_available')}"
"#{name} #{@show_name ? "- #{user_names}" : ''}"
else
"#{name} - #{I18n.t('availabilities.i_ve_reserved')}"
end

View File

@ -6,6 +6,7 @@ json.title slot.title
json.start slot.start_at.iso8601
json.end slot.end_at.iso8601
json.is_reserved slot.is_reserved
json.is_completed slot.full?
json.backgroundColor 'white'
json.availability_id slot.availability_id

View File

@ -769,6 +769,8 @@ en:
online_payment_info_html: "You can enable your members to book directly online, paying by card. Alternatively, you can restrict the booking and payment processes for administrators and managers."
enable_online_payment: "Enable online payment"
stripe_keys: "Stripe keys"
public_key: "Public key"
secret_key: "Secret key"
error_check_keys: "Error: please check your Stripe keys."
stripe_keys_saved: "Stripe keys successfully saved."
error_saving_stripe_keys: "Unable to save the Stripe keys. Please try again later."

View File

@ -142,7 +142,7 @@ class Reservations::RestrictedTest < ActionDispatch::IntegrationTest
end
assert_equal 422, response.status
assert_match /unable to pay/, response.body
assert_match(/invalid shopping cart/, response.body)
assert_equal reservations_count, Reservation.count
assert_equal invoices_count, Invoice.count