Class: Bistrochat::Reservations::Update

Inherits:
Object
  • Object
show all
Includes:
ApiHelpers, DefaultErrorContainer, ElasticAPM::SpanHelpers
Defined in:
app/services/bistrochat/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_bistrochat_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.



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

def initialize(reservation, tc_reservation_id, update_params)
  @new_reservation = reservation.decorate
  @bistrochat_reservation = find_bistrochat_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

#bistrochat_reservationObject (readonly)

Returns the value of attribute bistrochat_reservation.



11
12
13
# File 'app/services/bistrochat/reservations/update.rb', line 11

def bistrochat_reservation
  @bistrochat_reservation
end

#new_reservationObject (readonly)

Returns the value of attribute new_reservation.



11
12
13
# File 'app/services/bistrochat/reservations/update.rb', line 11

def new_reservation
  @new_reservation
end

#update_paramsObject (readonly)

Returns the value of attribute update_params.



11
12
13
# File 'app/services/bistrochat/reservations/update.rb', line 11

def update_params
  @update_params
end

Instance Method Details

#executeObject



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/bistrochat/reservations/update.rb', line 21

def execute
  errors.clear

  error_message = Bistrochat::ErrorMessages::DEFAULT_ERROR

  if new_reservation.blank?
    error_message = 'Reservation not found'
    unless Bistrochat::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 bistrochat_reservation.blank?
    error_message = "VendorReservation for reservation #{new_reservation.id} not found"
    unless Bistrochat::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_bistrochat_reservation(update_result.data['id'])
  if result.blank?
    error_message = "Error updating reservation #{bistrochat_reservation.reservation.id} in BistrochatReservation"
    unless Bistrochat::ErrorMessages::KNOWN_ERRORS.include?(error_message)
      APMErrorHandler.report("#{self.class} #{error_message}",
                             reservation_id: bistrochat_reservation.reservation.id)
    end
    BUSINESS_LOGGER.error("#{self.class} #{error_message}", reservation_id: bistrochat_reservation.reservation.id)
    errors.add(:base, error_message)

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

  ServiceResult.new data: result
end

#update_reservation_paramsObject



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

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