Skip to content

Commit

Permalink
同企業所属の研修生を取得するスコープを削除してメソッドを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
yuma-matsui committed Aug 31, 2022
1 parent fe0a0db commit 3bb376c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index
@completed_learnings = current_user.learnings.where(status: 3).includes(:practice).order(updated_at: :desc)
@inactive_students = User.with_attached_avatar.inactive_students_and_trainees.order(last_activity_at: :desc)
@job_seeking_users = User.with_attached_avatar.job_seeking.includes(:reports, :products, :works, :course, :company)
@collegue_trainees = User.with_attached_avatar.collegue_trainees(current_user).includes(:reports, :products, :comments)
@collegue_trainees = current_user.collegue_trainees&.with_attached_avatar&.includes(:reports, :products, :comments)
display_events_on_dashboard
display_welcome_message_for_adviser
set_required_fields
Expand Down
20 changes: 13 additions & 7 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,6 @@ class User < ApplicationRecord
scope :unretired, -> { where(retired_on: nil) }
scope :advisers, -> { where(adviser: true) }
scope :not_advisers, -> { where(adviser: false) }
scope :same_company, lambda { |user|
where(company_id: user.company_id)
}
scope :collegue_trainees, lambda { |user|
same_company(user).students_and_trainees
}
scope :students_and_trainees, lambda {
where(
admin: false,
Expand Down Expand Up @@ -666,8 +660,20 @@ def wip_exists?
products.wip.exists? || announcements.wip.exists? || events.wip.exists?
end

def belongs_company?
!company.nil?
end

def belongs_company_and_adviser?
adviser? && !company.nil?
adviser? && belongs_company?
end

def collegues
company.users if belongs_company?
end

def collegue_trainees
collegues.students_and_trainees if belongs_company_and_adviser?
end

private
Expand Down

0 comments on commit 3bb376c

Please sign in to comment.