Use _uid instead of _id to please Rails

This commit is contained in:
Darren Clarke 2026-01-19 16:51:51 +01:00
parent 87bb05fdd5
commit ac42d7df78
22 changed files with 151 additions and 50 deletions

View file

@ -150,7 +150,7 @@ class ChannelsCdrWhatsappController < ApplicationController
# Lookup customer with fallback chain:
# 1. Phone number in phone/mobile fields (preferred)
# 2. WhatsApp user ID in whatsapp_user_id field
# 2. WhatsApp user ID in whatsapp_uid field
# 3. User ID in phone/mobile fields (legacy - we used to store LIDs there)
customer = nil
if sender_phone_number.present?
@ -158,7 +158,7 @@ class ChannelsCdrWhatsappController < ApplicationController
customer ||= User.find_by(mobile: sender_phone_number)
end
if customer.nil? && sender_user_id.present?
customer = User.find_by(whatsapp_user_id: sender_user_id)
customer = User.find_by(whatsapp_uid: sender_user_id)
# Legacy fallback: user ID might be stored in phone field
customer ||= User.find_by(phone: sender_user_id)
customer ||= User.find_by(mobile: sender_user_id)
@ -172,7 +172,7 @@ class ChannelsCdrWhatsappController < ApplicationController
email: '',
password: '',
phone: sender_phone_number.presence || sender_user_id,
whatsapp_user_id: sender_user_id,
whatsapp_uid: sender_user_id,
note: 'CDR Whatsapp',
active: true,
role_ids: role_ids,
@ -181,9 +181,9 @@ class ChannelsCdrWhatsappController < ApplicationController
)
end
# Update whatsapp_user_id if we have it and customer doesn't
if sender_user_id.present? && customer.whatsapp_user_id.blank?
customer.update(whatsapp_user_id: sender_user_id)
# Update whatsapp_uid if we have it and customer doesn't
if sender_user_id.present? && customer.whatsapp_uid.blank?
customer.update(whatsapp_uid: sender_user_id)
end
# Update phone if we have it and customer only has user_id in phone field
if sender_phone_number.present? && customer.phone == sender_user_id