refactor: Atualiza chamadas de log para Rails.logger, refatora interpolação de strings e ajusta lógica de status de reserva.
This commit is contained in:
parent
88730d68bc
commit
c76c8d5c50
@ -116,7 +116,7 @@ module Captain
|
||||
contact = nil
|
||||
|
||||
# Try finding by phone
|
||||
contact = @account.contacts.find_by_phone_number(phone) if phone.present?
|
||||
contact = @account.contacts.find_by(phone_number: phone) if phone.present?
|
||||
|
||||
# Try finding by email
|
||||
contact = @account.contacts.find_by(email: email) if contact.nil? && email.present?
|
||||
@ -162,16 +162,12 @@ module Captain
|
||||
|
||||
return :scheduled unless check_in && check_out
|
||||
|
||||
if check_in.to_date == now.to_date
|
||||
:scheduled # Or 'awaiting_checkin' if we want to be more specific, but MVP 'scheduled' is usually 'Entrada'
|
||||
if now >= check_out
|
||||
:completed
|
||||
elsif now >= check_in && now < check_out
|
||||
:active # 'Hospedada'
|
||||
elsif now >= check_out
|
||||
:completed # 'Saída' / checkout done
|
||||
elsif now < check_in
|
||||
:scheduled
|
||||
:active
|
||||
else
|
||||
:scheduled # Default
|
||||
:scheduled
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
# This ensures the tool is enabled even if the console environment is broken.
|
||||
|
||||
Rails.application.config.after_initialize do
|
||||
puts '--- [FIX] Verifying CheckAvailabilityTool Config ---'
|
||||
Rails.logger.info '--- [FIX] Verifying CheckAvailabilityTool Config ---'
|
||||
|
||||
begin
|
||||
assistant = Captain::Assistant.first
|
||||
@ -13,14 +13,14 @@ Rails.application.config.after_initialize do
|
||||
if config.new_record? || !config.is_enabled
|
||||
config.is_enabled = true
|
||||
config.save!
|
||||
puts "--- [FIX] SUCCESS: check_availability ENABLED for #{assistant.name} ---"
|
||||
Rails.logger.info "--- [FIX] SUCCESS: check_availability ENABLED for #{assistant.name} ---"
|
||||
else
|
||||
puts "--- [FIX] SKIPPED: Already enabled for #{assistant.name} ---"
|
||||
Rails.logger.info "--- [FIX] SKIPPED: Already enabled for #{assistant.name} ---"
|
||||
end
|
||||
else
|
||||
puts '--- [FIX] WARNING: No Assistant found to fix. ---'
|
||||
Rails.logger.warn '--- [FIX] WARNING: No Assistant found to fix. ---'
|
||||
end
|
||||
rescue StandardError => e
|
||||
puts "--- [FIX] ERROR: #{e.message} ---"
|
||||
Rails.logger.error "--- [FIX] ERROR: #{e.message} ---"
|
||||
end
|
||||
end
|
||||
|
||||
@ -3,31 +3,29 @@ password = 'Password123!'
|
||||
|
||||
puts '=== DEBUGGING AUTH ==='
|
||||
user = User.find_by(email: email)
|
||||
puts 'User found via find_by: ' + (user ? 'YES' : 'NO')
|
||||
puts "User found via find_by: #{user ? 'YES' : 'NO'}"
|
||||
|
||||
if user
|
||||
puts 'User ID: ' + user.id.to_s
|
||||
puts 'User Email: ' + user.email
|
||||
puts "User ID: #{user.id}"
|
||||
puts "User Email: #{user.email}"
|
||||
|
||||
puts 'Checking User.from_email...'
|
||||
begin
|
||||
user_from_method = User.from_email(email)
|
||||
puts 'User found via User.from_email: ' + (user_from_method ? 'YES' : 'NO')
|
||||
rescue => e
|
||||
puts 'Error in User.from_email: ' + e.message
|
||||
puts "User found via User.from_email: #{user_from_method ? 'YES' : 'NO'}"
|
||||
rescue StandardError => e
|
||||
puts "Error in User.from_email: #{e.message}"
|
||||
end
|
||||
|
||||
|
||||
puts 'Checking valid_password?...'
|
||||
is_valid = user.valid_password?(password)
|
||||
puts 'Password valid: ' + is_valid.to_s
|
||||
|
||||
puts "Password valid: #{is_valid}"
|
||||
|
||||
puts 'Checking active_for_authentication?...'
|
||||
is_active = user.active_for_authentication?
|
||||
puts 'Active for auth: ' + is_active.to_s
|
||||
|
||||
if !is_active
|
||||
puts 'User inactive message: ' + user.inactive_message.to_s
|
||||
end
|
||||
puts "Active for auth: #{is_active}"
|
||||
|
||||
puts "User inactive message: #{user.inactive_message}" unless is_active
|
||||
else
|
||||
puts 'User not found!'
|
||||
end
|
||||
|
||||
@ -3,13 +3,13 @@ begin
|
||||
inbox = Inbox.first
|
||||
account = inbox.account
|
||||
puts "Testing with Account: #{account.id}, Inbox: #{inbox.id}"
|
||||
|
||||
|
||||
key = 'status_suites'
|
||||
|
||||
|
||||
# Create a temporary config or ensure it exists
|
||||
config = Jasmine::ToolConfig.find_or_initialize_by(
|
||||
account: account,
|
||||
inbox: inbox,
|
||||
account: account,
|
||||
inbox: inbox,
|
||||
tool_key: key
|
||||
)
|
||||
config.is_enabled = true
|
||||
@ -22,11 +22,11 @@ begin
|
||||
puts "Config saved. ID: #{config.id}, Token present: #{config.plug_play_token.present?}"
|
||||
|
||||
runner = Jasmine::ToolRunner.new(inbox, key)
|
||||
puts "Runner initialized. Running..."
|
||||
puts 'Runner initialized. Running...'
|
||||
result = runner.run
|
||||
puts "Result: #{result.inspect}"
|
||||
|
||||
rescue => e
|
||||
|
||||
rescue StandardError => e
|
||||
puts "CRITICAL ERROR: #{e.class} - #{e.message}"
|
||||
puts e.backtrace.join("\n")
|
||||
end
|
||||
|
||||
@ -38,11 +38,9 @@ module Captain
|
||||
actual_params = resolve_params(args, params)
|
||||
account_id = @conversation&.account_id || @assistant&.account_id
|
||||
|
||||
File.open(Rails.root.join('log/tool_debug.log'), 'a') do |f|
|
||||
f.puts "[#{Time.now}] STARTING CheckAvailabilityTool with params: #{actual_params}"
|
||||
f.puts "[#{Time.now}] PRICING COUNT: #{Captain::Pricing.where(account_id: account_id).count}"
|
||||
f.puts "[#{Time.now}] FIRST PRICING: #{Captain::Pricing.where(account_id: account_id).first.inspect}"
|
||||
end
|
||||
Rails.logger.info "[CheckAvailabilityTool] STARTING with params: #{actual_params}"
|
||||
Rails.logger.debug { "[CheckAvailabilityTool] PRICING COUNT: #{Captain::Pricing.where(account_id: account_id).count}" }
|
||||
Rails.logger.debug { "[CheckAvailabilityTool] FIRST PRICING: #{Captain::Pricing.where(account_id: account_id).first.inspect}" }
|
||||
|
||||
suite_category = actual_params[:suite]
|
||||
requested_duration = actual_params[:duration].presence # Don't default yet
|
||||
@ -57,7 +55,7 @@ module Captain
|
||||
|
||||
# [DATE RESOLUTION]
|
||||
target_date = resolve_target_date(actual_params)
|
||||
File.open(Rails.root.join('log/tool_debug.log'), 'a') { |f| f.puts "[#{Time.now}] RESOLVED DATE: #{target_date} | SUITE: #{suite_category}" }
|
||||
Rails.logger.info "[CheckAvailabilityTool] RESOLVED DATE: #{target_date} | SUITE: #{suite_category}"
|
||||
|
||||
# [DEBUG] Log the context
|
||||
current_inbox_id = @conversation&.inbox_id
|
||||
@ -96,9 +94,7 @@ module Captain
|
||||
# Use the matched category if found, otherwise stick to the original input (fallback)
|
||||
final_suite_category = matched_category || suite_category
|
||||
|
||||
File.open(Rails.root.join('log/tool_debug.log'), 'a') do |f|
|
||||
f.puts "[#{Time.now}] KEYWORD MATCH: Input='#{suite_category}' -> Resolved='#{final_suite_category}'"
|
||||
end
|
||||
Rails.logger.info "[CheckAvailabilityTool] KEYWORD MATCH: Input='#{suite_category}' -> Resolved='#{final_suite_category}'"
|
||||
|
||||
pricing_scope = Captain::Pricing.where(account_id: account_id)
|
||||
.where('suite_category ILIKE ?', final_suite_category)
|
||||
@ -130,7 +126,7 @@ module Captain
|
||||
|
||||
if available_options.present?
|
||||
msg = "Disponível! Para a suíte #{final_suite_category} em #{target_date&.strftime('%d/%m')}, tenho estas opções: #{available_options}. Pergunte qual duração o cliente prefere."
|
||||
File.open(Rails.root.join('log/tool_debug.log'), 'a') { |f| f.puts "[#{Time.now}] MENU MODE: #{msg}" }
|
||||
Rails.logger.info "[CheckAvailabilityTool] MENU MODE: #{msg}"
|
||||
return msg
|
||||
else
|
||||
msg = "Não encontrei tarifas para a suíte #{final_suite_category} nesta data. Confirme o nome da suíte."
|
||||
@ -146,7 +142,7 @@ module Captain
|
||||
final_price, unit: 'R$ ', separator: ',', delimiter: '.'
|
||||
)} (#{pricing.day_range})."
|
||||
persist_last_availability(final_suite_category, requested_duration, pricing, target_date)
|
||||
File.open(Rails.root.join('log/tool_debug.log'), 'a') { |f| f.puts "[#{Time.now}] SUCCESS: #{msg}" }
|
||||
Rails.logger.info "[CheckAvailabilityTool] SUCCESS: #{msg}"
|
||||
return msg
|
||||
else
|
||||
available_options = pricing_scope.map do |p|
|
||||
@ -163,9 +159,7 @@ module Captain
|
||||
return msg
|
||||
end
|
||||
rescue StandardError => e
|
||||
File.open(Rails.root.join('log/tool_debug.log'), 'a') do |f|
|
||||
f.puts "[#{Time.now}] CRITICAL ERROR in CheckAvailabilityTool: #{e.message}\n#{e.backtrace.first(5).join("\n")}"
|
||||
end
|
||||
Rails.logger.error "[CheckAvailabilityTool] CRITICAL ERROR: #{e.message}\n#{e.backtrace.first(5).join("\n")}"
|
||||
raise e
|
||||
end
|
||||
|
||||
|
||||
@ -9,12 +9,12 @@ if u
|
||||
if u.save
|
||||
puts 'User saved successfully.'
|
||||
else
|
||||
puts 'Error saving user: ' + u.errors.full_messages.join(', ')
|
||||
puts "Error saving user: #{u.errors.full_messages.join(', ')}"
|
||||
end
|
||||
|
||||
|
||||
# Reload and verify
|
||||
u.reload
|
||||
puts 'Password check immediately after save: ' + u.valid_password?(password).to_s
|
||||
puts "Password check immediately after save: #{u.valid_password?(password)}"
|
||||
else
|
||||
puts 'User NOT FOUND to reset password.'
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user