Class: Kidsmin::Api::V1::Admin::StatsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/kidsmin/api/v1/admin/stats_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/kidsmin/api/v1/admin/stats_controller.rb', line 8

def show
  render json: {
    families: {
      total:   Family.count,
      active:  Family.where.not(account_id: nil).count,
      pending: Family.where(account_id: nil).count,
    },
    children:     Child.count,
    events: {
      upcoming: Event.where("event_date >= ?", Time.current).count,
      total:    Event.count,
    },
    invitations: {
      pending: Invitation.where(accepted_at: nil)
                         .where("expires_at > ?", Time.current).count,
    },
    registrations: {
      this_month: Registration.where("created_at >= ?", Time.current.beginning_of_month).count,
    },
  }
end