Class: LesliAudit::UserService

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

Instance Method Summary collapse

Instance Method Details

#registrationsObject



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
# File 'app/services/lesli_audit/user_service.rb', line 36

def registrations

    period = "month"

    #Get filters from the request     
    group = query[:group]

    #Get period only if the request have filters
    period = group unless group.blank?

    registrations = []

    if ["day", "week", "month", "year"].include?(period)
        registrations = current_user..users
            .group("DATE_TRUNC('#{period}', created_at)")
            .count
            .map do |request|
                { 
                    :date => Date2.new(request[0]).date.to_s,
                    :count => request[1]
                }
        end
    end

    registrations
end