fix: Contacts page sort by created_at [CW-2262] (#7584)

Fixes the contacts page sort by created_at.
fixes: #7577
This commit is contained in:
Liam
2023-07-26 16:37:30 +01:00
committed by GitHub
parent 1d8341504a
commit 6c1ee4d965
2 changed files with 9 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
sort_on :name, internal_name: :order_on_name, type: :scope, scope_params: [:direction]
sort_on :phone_number, type: :string
sort_on :last_activity_at, internal_name: :order_on_last_activity_at, type: :scope, scope_params: [:direction]
sort_on :created_at, internal_name: :order_on_created_at, type: :scope, scope_params: [:direction]
sort_on :company, internal_name: :order_on_company_name, type: :scope, scope_params: [:direction]
sort_on :city, internal_name: :order_on_city, type: :scope, scope_params: [:direction]
sort_on :country, internal_name: :order_on_country_name, type: :scope, scope_params: [:direction]

View File

@@ -62,6 +62,14 @@ class Contact < ApplicationRecord
)
)
}
scope :order_on_created_at, lambda { |direction|
order(
Arel::Nodes::SqlLiteral.new(
sanitize_sql_for_order("\"contacts\".\"created_at\" #{direction}
NULLS LAST")
)
)
}
scope :order_on_company_name, lambda { |direction|
order(
Arel::Nodes::SqlLiteral.new(