Class: Decidim::ActionDelegator::Elections::ResultsController

Inherits:
ApplicationController
  • Object
show all
Includes:
SettingsHelper
Defined in:
app/controllers/decidim/action_delegator/elections/results_controller.rb

Instance Method Summary collapse

Methods included from SettingsHelper

#current_resource_settings, #delegations_for, #elections_question_responses_by_type, #elections_question_stats, #elections_question_weighted_responses, #participant_voted?, #settings_for

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#sum_of_weightsObject

TODO: authentication, ensure published results



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/decidim/action_delegator/elections/results_controller.rb', line 10

def sum_of_weights
  render json: {
    id: election.id,
    ongoing: election.ongoing?,
    questions: election.questions.map do |question|
      {
        id: question.id,
        body: translated_attribute(question.body),
        published_results: question.published_results?,
        response_options: elections_question_weighted_responses(question).map do |option|
          option.slice!(:id, :question_id, :body) unless election.result_published_questions.include?(question)
          option
        end
      }
    end
  }
end