Class: Kidspire::Api::V1::Admin::RegistrationsController

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

Instance Method Summary collapse

Instance Method Details

#indexObject

GET /api/v1/admin/registrations



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/kidspire/api/v1/admin/registrations_controller.rb', line 9

def index
  regs = Registration.includes(:family, :child, :event)
                     .joins(:event)
                     .order("kidspire_events.event_date DESC, kidspire_registrations.created_at DESC")
                     .page(params[:page]).per(100)

  render json: {
    registrations: regs.map { |r|
      {
        id:           r.id,
        family_name:  r.family.family_name || "#{r.family.primary_contact_last_name} Family",
        child_name:   "#{r.child.first_name} #{r.child.last_name}",
        child_grade:  r.child.grade_display,
        event_title:  r.event.title,
        event_date:   r.event.event_date,
        registered_at: r.created_at,
      }
    },
    meta: {
      total_count:  regs.total_count,
      current_page: regs.current_page,
      total_pages:  regs.total_pages,
    },
  }
end