Skip to content

Commit 62c4498

Browse files
committed
Add fetch_all_q_and_a function to research_output_presenter
- This function fetches all questions and answers belonging to a plan.
1 parent b3d9c2d commit 62c4498

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

app/presenters/api/v2/research_output_presenter.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ def fetch_q_and_a(themes:)
7171
end
7272
ret.select { |item| item[:description].present? }
7373
end
74+
75+
# Fetch all questions and answers from a plan, regardless of theme
76+
def fetch_all_q_and_a(plan:)
77+
return [] unless plan&.questions.present?
78+
79+
plan.questions.filter_map do |q|
80+
a = plan.answers.find { |ans| ans.question_id == q.id }
81+
next unless a.present? && !a.blank?
82+
83+
{
84+
title: "Question #{q.number || q.id}",
85+
question: q.text.to_s,
86+
answer: a.text.to_s
87+
}
88+
end
89+
end
7490
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
7591
end
7692
end

0 commit comments

Comments
 (0)