mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
This PR addresses several items listed in our rubocop_todo by implementing the necessary corrections and enhancements. As a result, we are now able to remove the rubocop_todo file entirely, streamlining our codebase and ensuring adherence to our coding standards. fixes: https://linear.app/chatwoot/issue/CW-1806/chore-rubocop-audit
31 lines
995 B
Ruby
31 lines
995 B
Ruby
# == Schema Information
|
|
#
|
|
# Table name: canned_responses
|
|
#
|
|
# id :integer not null, primary key
|
|
# content :text
|
|
# short_code :string
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# account_id :integer not null
|
|
#
|
|
|
|
class CannedResponse < ApplicationRecord
|
|
validates :content, presence: true
|
|
validates :short_code, presence: true
|
|
validates :account, presence: true
|
|
validates :short_code, uniqueness: { scope: :account_id }
|
|
|
|
belongs_to :account
|
|
|
|
scope :order_by_search, lambda { |search|
|
|
short_code_starts_with = sanitize_sql_array(['WHEN short_code ILIKE ? THEN 1', "#{search}%"])
|
|
short_code_like = sanitize_sql_array(['WHEN short_code ILIKE ? THEN 0.5', "%#{search}%"])
|
|
content_like = sanitize_sql_array(['WHEN content ILIKE ? THEN 0.2', "%#{search}%"])
|
|
|
|
order_clause = "CASE #{short_code_starts_with} #{short_code_like} #{content_like} ELSE 0 END"
|
|
|
|
order(Arel.sql(order_clause) => :desc)
|
|
}
|
|
end
|