Class: Tablecheck::Reservations::Update

Inherits:
Object
  • Object
show all
Includes:
DefaultErrorContainer, ApiHelpers
Defined in:
app/services/tablecheck/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_call, #channel, #find_tablecheck_vendor_application, #get_purpose, #headers, #parse_phone_number, #parse_user_or_guest_full_name, #parsed_vendor_name, #reservation_start_at, #send_error_availability_notification_to_staff

Constructor Details

#initialize(reservation, tc_reservation_id, update_params) ⇒ Update

Returns a new instance of Update.



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

def initialize(reservation, tc_reservation_id, update_params)
  @new_reservation = reservation.decorate
  @tablecheck_reservation = find_tablecheck_reservation(tc_reservation_id)
  validate_update_params(update_params)
  @update_params = update_params
  BUSINESS_LOGGER.set_business_context({ reservation_id: new_reservation.id })
end

Instance Attribute Details

#new_reservationObject (readonly)

Returns the value of attribute new_reservation.



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

def new_reservation
  @new_reservation
end

#tablecheck_reservationObject (readonly)

Returns the value of attribute tablecheck_reservation.



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

def tablecheck_reservation
  @tablecheck_reservation
end

#update_paramsObject (readonly)

Returns the value of attribute update_params.



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

def update_params
  @update_params
end

Instance Method Details

#executeObject



20
21
22
23
24
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/tablecheck/reservations/update.rb', line 20

def execute
  errors.clear

  error_message = Tablecheck::ErrorMessages::DEFAULT_ERROR

  if new_reservation.blank?
    error_message = 'Reservation not found'
    unless Tablecheck::ErrorMessages::KNOWN_ERRORS.include?(error_message)
      APMErrorHandler.report("#{self.class} #{error_message}")
    end
    BUSINESS_LOGGER.error("#{self.class} #{error_message}")
    errors.add(:base, error_message)

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

  if tablecheck_reservation.blank?
    error_message = "VendorReservation for reservation #{new_reservation.id} not found"
    unless Tablecheck::ErrorMessages::KNOWN_ERRORS.include?(error_message)
      APMErrorHandler.report("#{self.class} #{error_message}", reservation_id: new_reservation.id)
    end
    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

  update_result = update_reservation(update_reservation_params)
  unless update_result.success?
    error_message = update_result.message
    errors.add(:base, error_message)

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

  result = update_old_tablecheck_reservation(update_result.data['id'])
  if result.blank?
    error_message = "Error updating reservation #{tablecheck_reservation.reservation.id} in TablecheckReservation"
    unless Tablecheck::ErrorMessages::KNOWN_ERRORS.include?(error_message)
      APMErrorHandler.report("#{self.class} #{error_message}", reservation_id: tablecheck_reservation.reservation.id,
                                                               update_reservation_params: update_reservation_params)
    end
    BUSINESS_LOGGER.error("#{self.class} #{error_message}", reservation_id: tablecheck_reservation.reservation.id,
                                                            update_params: update_reservation_params)
    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
# File 'app/services/tablecheck/reservations/update.rb', line 72

def update_reservation_params
  notes = VendorsService::GenerateMemoService.new(new_reservation).execute

  {
    pax_adult: update_params[:pax_adult],
    pax_child: update_params[:pax_child],
    pax: update_params[:pax],
    start_at: update_params[:start_at],
    memo2: notes,
    purpose: get_purpose(update_params[:occasion].to_s),
    ref: new_reservation.id,
  }
end