Class: LesliAudit::Account::ActivityServices

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

Instance Method Summary collapse

Instance Method Details

#indexObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/services/lesli_audit/account/activity_services.rb', line 36

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

    activities = current_user..activities

    activities = activities.select(
        :id,
        :title,
        :description,
        :system_process,
        :system_module,
        "payload ->'to'->>0 as send_to",
        Date2.new.date_time.db_timestamps()
    )

    # search if search params was sent
    unless search_string.blank?
        activities = activities.where(["
            system_module like :search_string 
            or system_process like :search_string 
            or description like :search_string 
            or title like :search_string 
            or payload->'to'->>0 like :search_string",
        ].join(" or "), { 
            search_string: "%#{search_string}%"
        }) 
    end

    activities.page(query[:pagination][:page])
    .per(query[:pagination][:perPage])
    .order(created_at: :desc)
end