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