Class: Users::RegistrationServices

Inherits:
Lesli::ApplicationLesliService
  • Object
show all
Defined in:
app/services/lesli_audit/users/registration_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
# File 'app/services/lesli_audit/users/registration_services.rb', line 41

def index 
    period = 'month'
    #Get filters from http request     
    group = query[:group]
    #Get period only if the request have filters
    unless group.blank?
        period = group
    end

    unless period.blank? || (period != 'day' && period != 'week' && period != 'month' && period != 'year')
        registrations = current_user..users.group("DATE_TRUNC('#{period}', created_at)")
        registrations.order("date_trunc_#{period}_created_at DESC").count.map do |request|
            { 
                :date => Date2.new(request[0]).date.to_s,
                :count => request[1]
            }
        end
    end
end