class Admin::Communication::StudentsController < Admin::Communication::Controller
  def index
    render_success :ok, json: students.map { |s| student_props(s) }
  end

  private
    def students
      current_school.students
        .joins(:primary_email_address)
        .by_grade(params[:grade])
        .by_categories(params[:category_ids])
        .current_status(current_school, params[:current])
    end

    def student_props(student)
      {
        id: student.id,
        email: student.email,
        name: student.full_name(:reverse),
        type: :student
      }
    end
end
