Show taggings in API

This commit is contained in:
Alberto Miedes Garcés
2017-01-26 10:48:05 +01:00
parent 83267330a7
commit 69fc161b83
3 changed files with 10 additions and 9 deletions

View File

@@ -1,7 +0,0 @@
class Tag < ActsAsTaggableOn::Tag
def self.public_for_api
where("kind IS NULL OR kind = 'category'")
end
end

View File

@@ -22,6 +22,7 @@ Debate:
comments: [Comment]
public_author: User
votes: [Vote]
tags: ["ActsAsTaggableOn::Tag"]
Proposal:
fields:
id: integer
@@ -44,6 +45,7 @@ Proposal:
proposal_notifications: [ProposalNotification]
public_author: User
votes: [Vote]
tags: ["ActsAsTaggableOn::Tag"]
Comment:
fields:
id: integer
@@ -69,7 +71,7 @@ ProposalNotification:
proposal_id: integer
created_at: string
proposal: Proposal
Tag:
ActsAsTaggableOn::Tag:
fields:
id: integer
name: string

View File

@@ -20,6 +20,8 @@ module ActsAsTaggableOn
Tag.class_eval do
include Graphqlable
def increment_custom_counter_for(taggable_type)
Tag.increment_counter(custom_counter_field_name_for(taggable_type), id)
end
@@ -42,10 +44,14 @@ module ActsAsTaggableOn
ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'SpendingProposal').includes(:taggings).order(:name).uniq
end
def self.public_for_api
where("kind IS NULL OR kind = 'category'")
end
private
def custom_counter_field_name_for(taggable_type)
"#{taggable_type.underscore.pluralize}_count"
end
end
end
end