Files
nairobi/app/models/vote.rb
Alberto Miedes Garcés f2eb8724d3 Remove duplicated scopes
2017-01-13 00:54:52 +01:00

18 lines
685 B
Ruby

class Vote < ActsAsVotable::Vote
def self.public_for_api
joins("FULL OUTER JOIN debates ON votable_type = 'Debate' AND votable_id = debates.id").
joins("FULL OUTER JOIN proposals ON votable_type = 'Proposal' AND votable_id = proposals.id").
joins("FULL OUTER JOIN comments ON votable_type = 'Comment' AND votable_id = comments.id").
where("votable_type = 'Proposal' AND proposals.hidden_at IS NULL OR votable_type = 'Debate' AND debates.hidden_at IS NULL OR votable_type = 'Comment' AND comments.hidden_at IS NULL")
end
def public_voter
votable.votes_above_threshold? ? voter : nil
end
def public_timestamp
self.created_at.change(min: 0)
end
end