# NOTE: This has to be run after assignment and group generations since it is
# dependant on groups existing for Assignment 1.

namespace :db do
  desc 'Create peer reviews and related data'
  task peer_reviews: :environment do
    puts 'Creating A1 Peer Review and updating A1 to have the peer review'
    a1 = Assignment.find_by(short_identifier: 'A1')
    a1.assignment_properties.update(has_peer_review: true) # Creates 'a1pr' via callback.

    a1pr = a1.pr_assignment
    a1pr.clone_groupings_from(a1.id)
    a1pr.update(is_hidden: false)

    selected_reviewer_group_ids = a1pr.groupings.map(&:id)
    selected_reviewee_group_ids = a1.groupings.map(&:id)

    PeerReviewsController.new.perform_random_assignment(
      a1pr, 3, selected_reviewer_group_ids, selected_reviewee_group_ids
    )
  end
end

# NOTE: This has to be run after assignment and group generations since it is
# dependant on groups existing for Assignment 1.

namespace :db do
  desc 'Create peer reviews and related data'
  task peer_reviews: :environment do
    puts 'Creating A1 Peer Review and updating A1 to have the peer review'
    a1 = Assignment.find_by(short_identifier: 'A1')
    a1.update(has_peer_review: true) # Creates 'a1pr' via callback.

    a1pr = a1.pr_assignment
    a1pr.clone_groupings_from(a1.id)
    a1pr.update(is_hidden: false)

    selected_reviewer_group_ids = a1pr.groupings.map(&:id)
    selected_reviewee_group_ids = a1.groupings.map(&:id)

    PeerReviewsController.new.perform_random_assignment(
      a1pr, 3, selected_reviewer_group_ids, selected_reviewee_group_ids
    )
  end
end

Fix peer review creation in seed data
seed: Fix peer review creation in seed data
