Class: Users::LogServices

Inherits:
Lesli::ApplicationLesliService
  • Object
show all
Defined in:
app/services/lesli_audit/users/log_services.rb

Instance Method Summary collapse

Instance Method Details

#indexHash

Returns Paginated list of the records.

Parameters:

  • Has (query)

    of the formated queries/filters that will be applied to filter data

Returns:

  • (Hash)

    Paginated list of the records



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/services/lesli_audit/users/log_services.rb', line 41

def index 
    search_string = query[:search].downcase.gsub(" ","%") unless query[:search].blank?

    records = current_user..users.joins(:logs)
    #records = records.where("users.email = ?", query[:filters][:user]) unless query[:filters][:user].blank?
    records = records.where("title like :search or description like :search", { search: "%#{search_string}%"}) unless search_string.blank?
    records = records.select(
        :id,
        "users.id as user_id",
        "users.email",
        :title,
        :description,
        Date2.new.date_time.db_timestamps("user_logs")
    )
    .page(query[:pagination][:page])
    .per(query[:pagination][:perPage])
    .order("user_logs.created_at DESC")

    records
end