Skip to content

Commit

Permalink
fix participants in project
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Sep 11, 2024
1 parent 51003c5 commit 39d6a3a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,18 @@ def should_generate_new_friendly_id?
end

def participants
users = statement_of_works.active_in_period(Time.zone.today,
Time.zone.today).map(&:requirements)
.flatten.map(&:assignments).flatten.map(&:user).flatten
User.where(id: users.map(&:id)).distinct
date = Time.zone.today

# Get the active statement of works in the given period
active_sows = statement_of_works.active_in_period(date, date)

# Find all the related requirements that are active in the period while keeping it as an ActiveRecord relation
active_requirements = Requirement.where(statement_of_work_id: active_sows.pluck(:id))
.active_in_period(date, date)

# Get the users related to assignments from the active requirements
User.joins(assignments: :requirement)
.where(assignments: { requirement_id: active_requirements.pluck(:id) })
.distinct
end
end

0 comments on commit 39d6a3a

Please sign in to comment.