Class: Decidim::Surveys::UserResponsesSerializer

Inherits:
Exporters::Serializer
  • Object
show all
Includes:
TranslationsHelper
Defined in:
lib/decidim/surveys/user_responses_serializer.rb

Instance Method Summary collapse

Instance Method Details

#serializeObject

Public: Exports a hash with the serialized data for the user response.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/decidim/surveys/user_responses_serializer.rb', line 9

def serialize
  # Returns a csv export of surveys responses only if they have been published.
  response = resource
  {
    id: response.session_token,
    created_at: response.created_at,
    ip_hash: response.ip_hash,
    user_status: I18n.t(response.decidim_user_id.present? ? "registered" : "unregistered", scope: "decidim.open_data.help.published_survey_user_responses"),
    question: question_text(response),
    body: normalize_body(response)
  }
end