crowdAI/crowdai

View on GitHub
app/models/notification.rb

Summary

Maintainability
A
0 mins
Test Coverage
class Notification < ApplicationRecord
  belongs_to :participant
  belongs_to :notifiable, polymorphic: true

  scope :pristine, -> { where(is_new: true) }
  scope :recent, -> { order(created_at: :desc) }
  scope :unread, -> { where(read_at: nil) }

  validates :notification_type, presence: true

  NOTIFICATION_TYPE = {
    'Comment' => :comment,
    'Mention' => :mention,
    'Graded' => :graded,
    'Grading Failed' => :grading_failed,
    'Leaderboard' => :leaderboard,
    'Article' => :article
  }

  def read?
    self.read_at.present?
  end

end