Sha256: 8c7b2a763a9c9622db58057091f5ecbd9ae6a5cc5ee9ff880eb5087ceabbd2bf

Contents?: true

Size: 1.37 KB

Versions: 13

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Decidim
  module Blogs
    class BlogsType < Decidim::Api::Types::BaseObject
      implements Decidim::Core::ComponentInterface

      graphql_name "Blogs"
      description "A blogs component of a participatory space."

      field :posts, type: Decidim::Blogs::PostType.connection_type, description: "List all posts", connection: true, null: false do
        argument :order, Decidim::Blogs::PostInputSort, "Provides several methods to order the results", required: false
        argument :filter, Decidim::Blogs::PostInputFilter, "Provides several methods to filter the results", required: false
      end

      field :post, type: Decidim::Blogs::PostType, description: "Finds one post", null: true do
        argument :id, GraphQL::Types::ID, "The ID of the post", required: true
      end

      def posts(filter: {}, order: {})
        base_query = Decidim::Core::ComponentListBase.new(model_class: Post).call(object, { filter:, order: }, context)
        if context[:current_user]&.admin?
          base_query
        else
          base_query.published
        end
      end

      def post(id:)
        scope =
          if context[:current_user]&.admin?
            Post
          else
            Post.published
          end

        Decidim::Core::ComponentFinderBase.new(model_class: scope).call(object, { id: }, context)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-blogs-0.29.1 lib/decidim/api/blogs_type.rb
decidim-blogs-0.28.4 lib/decidim/api/blogs_type.rb
decidim-blogs-0.29.0 lib/decidim/api/blogs_type.rb
decidim-blogs-0.28.3 lib/decidim/api/blogs_type.rb
decidim-blogs-0.29.0.rc4 lib/decidim/api/blogs_type.rb
decidim-blogs-0.29.0.rc3 lib/decidim/api/blogs_type.rb
decidim-blogs-0.29.0.rc2 lib/decidim/api/blogs_type.rb
decidim-blogs-0.29.0.rc1 lib/decidim/api/blogs_type.rb
decidim-blogs-0.28.2 lib/decidim/api/blogs_type.rb
decidim-blogs-0.28.1 lib/decidim/api/blogs_type.rb
decidim-blogs-0.28.0 lib/decidim/api/blogs_type.rb
decidim-blogs-0.28.0.rc5 lib/decidim/api/blogs_type.rb
decidim-blogs-0.28.0.rc4 lib/decidim/api/blogs_type.rb