Simplify methods to get API-public records
Just like we did to tags in commit 2e863fdc5.
This commit is contained in:
@@ -37,12 +37,7 @@ class Comment < ApplicationRecord
|
||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
scope :public_for_api, -> do
|
||||
not_valuations
|
||||
.where(%{(comments.commentable_type = 'Debate' and comments.commentable_id in (?)) or
|
||||
(comments.commentable_type = 'Proposal' and comments.commentable_id in (?)) or
|
||||
(comments.commentable_type = 'Poll' and comments.commentable_id in (?))},
|
||||
Debate.public_for_api.pluck(:id),
|
||||
Proposal.public_for_api.pluck(:id),
|
||||
Poll.public_for_api.pluck(:id))
|
||||
.where(commentable: [Debate.public_for_api, Proposal.public_for_api, Poll.public_for_api])
|
||||
end
|
||||
|
||||
scope :sort_by_most_voted, -> { order(confidence_score: :desc, created_at: :desc) }
|
||||
|
||||
@@ -10,7 +10,7 @@ class ProposalNotification < ApplicationRecord
|
||||
validates :proposal, presence: true
|
||||
validate :minimum_interval
|
||||
|
||||
scope :public_for_api, -> { where(proposal_id: Proposal.public_for_api.pluck(:id)) }
|
||||
scope :public_for_api, -> { where(proposal: Proposal.public_for_api) }
|
||||
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
|
||||
scope :sort_by_moderated, -> { reorder(moderated: :desc) }
|
||||
|
||||
|
||||
@@ -5,12 +5,7 @@ ActsAsVotable::Vote.class_eval do
|
||||
belongs_to :budget_investment, foreign_key: "votable_id", class_name: "Budget::Investment"
|
||||
|
||||
scope :public_for_api, -> do
|
||||
where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or
|
||||
(votes.votable_type = 'Proposal' and votes.votable_id in (?)) or
|
||||
(votes.votable_type = 'Comment' and votes.votable_id in (?))},
|
||||
Debate.public_for_api.pluck(:id),
|
||||
Proposal.public_for_api.pluck(:id),
|
||||
Comment.public_for_api.pluck(:id))
|
||||
where(votable: [Debate.public_for_api, Proposal.public_for_api, Comment.public_for_api])
|
||||
end
|
||||
|
||||
def value
|
||||
|
||||
Reference in New Issue
Block a user