Module: QuickEditReservation

Includes:
ActionView::Helpers::DateHelper
Included in:
ReservationGuestUpdatesController, ReservationsController
Defined in:
app/controllers/concerns/quick_edit_reservation.rb

Overview

typed: ignore

Instance Method Summary collapse

Instance Method Details

#validate_guest_edit(reservation) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/concerns/quick_edit_reservation.rb', line 5

def validate_guest_edit(reservation)
  next_path = nil
  flash = nil

  unless reservation.active
    next_path = check_reservations_path
    flash = { notice: t('views.booking.expired_link') }
  end

  if reservation.is_past? && !reservation.active
    next_path = check_reservations_path
    flash = { notice: t('reservation.editing_past_reservation2') }
  end

  if !reservation.allowed_to_rectify?
    restaurant = reservation.restaurant
    time_needed = distance_of_time_in_words restaurant.time_in_advance_to_rectify.minutes

    next_path = check_reservations_path
    flash = { notice: t('reservation.too_quick_to_rectify', time_needed: time_needed, phone: restaurant.phone) }
  end

  if next_path.nil?
    { success: true }
  else
    { success: false, next_path: next_path, flash: flash }
  end
end