zhishi-engine/zhishi-backend

View on GitHub
app/serializers/notifications/comment_serializer.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Notifications
  class CommentSerializer < ActiveModel::Serializer
    attributes :id, :content, :url, :type
    has_one :user
    has_one :parent

    private
      def url
        resource_name = object.comment_on.model_name.route_key
        resource_id = object.comment_on_id
        comment_url(object, resource_name: resource_name, resource_id: resource_id)
      end

      def type
        'Comment'
      end

      def parent
        object.comment_on
      end
  end
end