chore: Support multiple values for automation message content (#7871)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -23,8 +23,8 @@ class FilterService
|
||||
@filter_values["value_#{current_index}"] = filter_values(query_hash)
|
||||
equals_to_filter_string(query_hash[:filter_operator], current_index)
|
||||
when 'contains', 'does_not_contain'
|
||||
@filter_values["value_#{current_index}"] = "%#{string_filter_values(query_hash)}%"
|
||||
like_filter_string(query_hash[:filter_operator], current_index)
|
||||
@filter_values["value_#{current_index}"] = values_for_ilike(query_hash)
|
||||
ilike_filter_string(query_hash[:filter_operator], current_index)
|
||||
when 'is_present'
|
||||
@filter_values["value_#{current_index}"] = 'IS NOT NULL'
|
||||
when 'is_not_present'
|
||||
@@ -47,8 +47,6 @@ class FilterService
|
||||
query_hash['values'].map { |x| Conversation.statuses[x.to_sym] }
|
||||
when 'message_type'
|
||||
query_hash['values'].map { |x| Message.message_types[x.to_sym] }
|
||||
when 'content'
|
||||
string_filter_values(query_hash)
|
||||
else
|
||||
case_insensitive_values(query_hash)
|
||||
end
|
||||
@@ -62,6 +60,15 @@ class FilterService
|
||||
end
|
||||
end
|
||||
|
||||
def values_for_ilike(query_hash)
|
||||
if query_hash['values'].is_a?(Array)
|
||||
query_hash['values']
|
||||
.map { |item| "%#{item.strip}%" }
|
||||
else
|
||||
["%#{query_hash['values'].strip}%"]
|
||||
end
|
||||
end
|
||||
|
||||
def string_filter_values(query_hash)
|
||||
return query_hash['values'][0].downcase if query_hash['values'].is_a?(Array)
|
||||
|
||||
@@ -149,6 +156,12 @@ class FilterService
|
||||
"NOT IN (:value_#{current_index})"
|
||||
end
|
||||
|
||||
def ilike_filter_string(filter_operator, current_index)
|
||||
return "ILIKE ANY (ARRAY[:value_#{current_index}])" if %w[contains].include?(filter_operator)
|
||||
|
||||
"NOT ILIKE ALL (ARRAY[:value_#{current_index}])"
|
||||
end
|
||||
|
||||
def like_filter_string(filter_operator, current_index)
|
||||
return "LIKE :value_#{current_index}" if %w[contains starts_with].include?(filter_operator)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user