Sha256: b0a5bf4c68b3360f39604c89ba58becf8bfcdebb51c107e7b5adc93e941e2608

Contents?: true

Size: 1.13 KB

Versions: 21

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Decidim
  module Forms
    class DataPortabilityUserAnswersSerializer < Decidim::Exporters::Serializer
      include Decidim::TranslationsHelper
      # Serializes an user answer for data portability
      def serialize
        {
          id: resource.id,
          user: {
            name: resource.user.name,
            email: resource.user.email
          },
          questionnaire: {
            id: resource.question.questionnaire.id,
            title: translated_attribute(resource.question.questionnaire.title),
            description: translated_attribute(resource.question.questionnaire.description),
            tos: translated_attribute(resource.question.questionnaire.tos)
          },
          question: {
            id: resource.question.id,
            body: translated_attribute(resource.question.body),
            description: translated_attribute(resource.question.description)
          },
          answer: normalize_body(resource)
        }
      end

      private

      def normalize_body(resource)
        resource.body || resource.choices.pluck(:body)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
decidim-forms-0.23.6 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.23.5 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.23.4 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.23.3 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.23.2 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.23.1 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.23.1.rc1 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.23.0 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.22.0 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.21.0 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.20.1 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.20.0 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.19.1 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.18.1 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.19.0 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.17.2 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.18.0 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.17.1 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.16.1 lib/decidim/forms/data_portability_user_answers_serializer.rb
decidim-forms-0.17.0 lib/decidim/forms/data_portability_user_answers_serializer.rb