Follow up: Pull request #495 - refactoring broke level based lookup.

This commit is contained in:
Thorsten Eckel 2016-12-06 15:27:07 +01:00
parent e524a82aeb
commit d34aae41f1

View file

@ -25,6 +25,9 @@ module Cti
o_id: data[:o_id], o_id: data[:o_id],
user_id: data[:user_id], user_id: data[:user_id],
) )
# p "------------------"
# p record
return record if !record.new_record? return record if !record.new_record?
record.comment = data[:comment] record.comment = data[:comment]
record.save! record.save!
@ -41,11 +44,23 @@ returns
=end =end
def self.lookup(caller_id) def self.lookup(caller_id)
where(caller_id: caller_id)
.group(:user_id, :id) \ result = []
# first known, then maybe, last others ['known', 'maybe', nil].each { |level|
.order("level != 'known', level != 'maybe', id DESC")
.limit(20) search_params = {
caller_id: caller_id,
}
if level
search_params[:level] = level
end
result = Cti::CallerId.where(search_params).group(:user_id, :id).order(id: 'DESC').limit(20)
break if result.present?
}
result
end end
=begin =begin