From f9eabf9abd644491ba6c6b324e1bfd628e800323 Mon Sep 17 00:00:00 2001 From: Theodor Vararu Date: Fri, 27 Sep 2024 18:28:16 +0300 Subject: [PATCH] Fix add_health_questions to work with programmes This was written back when we had just one programme per team. --- lib/tasks/add_health_questions.rake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/tasks/add_health_questions.rake b/lib/tasks/add_health_questions.rake index b524f4535..5096f5b99 100644 --- a/lib/tasks/add_health_questions.rake +++ b/lib/tasks/add_health_questions.rake @@ -19,7 +19,12 @@ DESC task :add_health_questions, %i[team_id vaccine_id replace] => :environment do |_task, args| team = Team.find(args[:team_id]) - vaccine = team.programme.vaccines.find(args[:vaccine_id]) + vaccine = + team + .programmes + .flat_map(&:vaccines) + .find { |v| v.id == args[:vaccine_id].to_i } + raise "Vaccine not found for the given team" if vaccine.nil? existing_health_questions = vaccine.health_questions.in_order puts "Existing health questions for #{team.name}'s #{vaccine.type} vaccine #{vaccine.brand}" if existing_health_questions.any?