Class: SevenRooms::Reservations::Update

Inherits:
Object
  • Object
show all
Includes:
DefaultErrorContainer, ApiHelpers
Defined in:
app/services/seven_rooms/reservations/update.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DefaultErrorContainer

#error, #error_message_simple, #merge_errors

Methods included from ApiHelpers

#api_uri, #auth_headers, #common_headers, #find_seven_rooms_vendor_application, #parse_user_or_guest_full_name, #parsed_vendor_name, #send_error_availability_notification_to_staff, #sevenrooms_credit_card_error?, #standardize_or_default_phone

Constructor Details

#initialize(reservation, sr_reservation_id, update_params) ⇒ Update

Returns a new instance of Update.



12
13
14
15
16
17
# File 'app/services/seven_rooms/reservations/update.rb', line 12

def initialize(reservation, sr_reservation_id, update_params)
  @new_reservation = reservation.decorate if reservation.present?
  @seven_rooms_reservation = find_seven_rooms_reservation(sr_reservation_id)
  validate_update_params(update_params)
  @update_params = update_params
end

Instance Attribute Details

#new_reservationObject (readonly)

Returns the value of attribute new_reservation.



10
11
12
# File 'app/services/seven_rooms/reservations/update.rb', line 10

def new_reservation
  @new_reservation
end

#seven_rooms_reservationObject (readonly)

Returns the value of attribute seven_rooms_reservation.



10
11
12
# File 'app/services/seven_rooms/reservations/update.rb', line 10

def seven_rooms_reservation
  @seven_rooms_reservation
end

#update_paramsObject (readonly)

Returns the value of attribute update_params.



10
11
12
# File 'app/services/seven_rooms/reservations/update.rb', line 10

def update_params
  @update_params
end

Instance Method Details

#executeObject

Executes the update of a reservation in SevenRooms.

Returns a ServiceResult object with the following attributes:

  • data: The result of creating the SevenRoomsReservation record.

  • errors: Any errors that occurred during the execution.

  • message: A message indicating the result of the execution.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/services/seven_rooms/reservations/update.rb', line 25

def execute
  errors.clear
  error_message = SevenRooms::ErrorMessages::DEFAULT_ERROR

  # Validate reservation
  validation_result = validate_reservation
  unless validation_result.success?
    error_message = validation_result.message
    errors.add(:base, error_message)

    return ServiceResult.new errors: errors, message: error_message
  end

  update_result = update_reservation(validation_result.data[:concierge_id],
                                     validation_result.data[:venue_id],
                                     update_reservation_params)
  unless update_result.success?
    error_message = update_result.message
    # send notif to ops team if error related to inventory
    if new_reservation.modified_by.present? && new_reservation.modified_by.to_sym == :user
      send_error_availability_notification_to_staff(new_reservation,
                                                    error_message,
                                                    update_params[:date],
                                                    update_params[:start_time],
                                                    update_params[:party_size],
                                                    :update)
    end
    APMErrorHandler.report("#{self.class} #{error_message}") unless SevenRooms::ErrorMessages::KNOWN_ERRORS.include?(error_message)
    BUSINESS_LOGGER.error("#{self.class} #{error_message}", reservation_id: new_reservation.id)
    errors.add(:base, error_message)

    return ServiceResult.new errors: errors, message: error_message
  end

  result = update_old_seven_rooms_reservation(update_result.data['reservation_id'])
  if result.blank?
    error_message = "Error updating reservation #{new_reservation.id} in SevenRoomsReservation"
    APMErrorHandler.report("#{self.class} #{error_message}") unless SevenRooms::ErrorMessages::KNOWN_ERRORS.include?(error_message)
    BUSINESS_LOGGER.error("#{self.class} #{error_message}", reservation_id: new_reservation.id)
    errors.add(:base, error_message)

    return ServiceResult.new errors: errors, message: error_message
  end

  ServiceResult.new data: result
end

#update_reservation_paramsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/services/seven_rooms/reservations/update.rb', line 72

def update_reservation_params
  notes = VendorsService::GenerateMemoService.new(new_reservation).execute
  {
    reservation_id: seven_rooms_reservation.supplier_reservation_id,
    date: update_params[:date].to_s,
    time: update_params[:start_time].strftime('%H:%M'),
    party_size: update_params[:party_size],
    notes: notes,
    send_client_email: false,
    send_reminder_email: false,
    bypass_duplicate_reservation_check: true,
    bypass_required_contact_fields: true,
    bypass_editable_cutoff: true,
  }
end