models: refactor class methods into scopes.
This commit is contained in:
@@ -10,19 +10,11 @@ class PostAppeal < ApplicationRecord
|
||||
validate :validate_creator_is_not_limited
|
||||
validates_uniqueness_of :creator_id, :scope => :post_id, :message => "have already appealed this post"
|
||||
|
||||
scope :resolved, -> { where(post: Post.undeleted.unflagged) }
|
||||
scope :unresolved, -> { where(post: Post.deleted.or(Post.flagged)) }
|
||||
scope :recent, -> { where("post_appeals.created_at >= ?", 1.day.ago) }
|
||||
|
||||
module SearchMethods
|
||||
def resolved
|
||||
joins(:post).where("posts.is_deleted = false and posts.is_flagged = false")
|
||||
end
|
||||
|
||||
def unresolved
|
||||
joins(:post).where("posts.is_deleted = true or posts.is_flagged = true")
|
||||
end
|
||||
|
||||
def recent
|
||||
where("created_at >= ?", 1.day.ago)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
q = q.search_attributes(params, :creator, :post, :reason)
|
||||
|
||||
Reference in New Issue
Block a user