Sha256: 46df62cc40cd004d9aeaa94735e37defa38862d27060e710e26eb71b57b187ab

Contents?: true

Size: 1.56 KB

Versions: 31

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    class CommentVoteSerializer < Decidim::Exporters::Serializer
      include Decidim::ResourceHelper

      # Serializes a comment
      def serialize
        {
          id: resource.id,
          weight: resource.weight,
          comment: {
            id: resource.comment.id,
            created_at: resource.comment.created_at,
            body: resource.comment.body,
            author: {
              id: resource.comment.author.id,
              name: resource.comment.author.name
            },
            alignment: resource.comment.alignment,
            depth: resource.comment.depth,
            user_group: {
              id: resource.comment.user_group.try(:id),
              name: resource.comment.user_group.try(:name)
            },
            commentable_id: resource.comment.decidim_commentable_id,
            commentable_type: resource.comment.decidim_commentable_type,
            root_commentable_url: root_commentable_url

          },
          created_at: resource.created_at,
          updated_at: resource.updated_at
        }
      end

      private

      def root_commentable_url
        @root_commentable_url ||= if resource.comment.root_commentable&.respond_to?(:polymorphic_resource_url)
                                    resource.comment.root_commentable.polymorphic_resource_url
                                  else
                                    ResourceLocatorPresenter.new(resource.comment.root_commentable).url
                                  end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-comments-0.26.8 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.26.7 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.26.5 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.26.4 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.26.3 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.26.2 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.26.1 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.26.0 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.26.0.rc2 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.26.0.rc1 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.25.2 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.25.1 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.25.0 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.25.0.rc4 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.25.0.rc3 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.25.0.rc2 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.25.0.rc1 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.24.3 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.23.6 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.24.2 lib/decidim/comments/comment_vote_serializer.rb