models: refactor class methods into scopes.

This commit is contained in:
evazion
2020-02-17 02:10:08 -06:00
parent 9a8aa1990d
commit 83a0cb0a71
12 changed files with 45 additions and 126 deletions

View File

@@ -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)