demarches-normaliennes/app/models/notification.rb

42 lines
1.1 KiB
Ruby
Raw Normal View History

2016-12-21 17:26:31 +01:00
class Notification < ActiveRecord::Base
enum type_notif: {
2017-05-26 21:32:43 +02:00
commentaire: 'commentaire',
cerfa: 'cerfa',
piece_justificative: 'piece_justificative',
champs: 'champs',
submitted: 'submitted',
2017-09-27 12:14:41 +02:00
avis: 'avis',
annotations_privees: 'annotations_privees'
2017-05-26 21:32:43 +02:00
}
2017-08-30 15:31:36 +02:00
DEMANDE = %w(cerfa piece_justificative champs submitted)
2017-09-27 11:55:56 +02:00
AVIS = %w(avis)
2017-08-30 15:31:36 +02:00
MESSAGERIE = %w(commentaire)
ANNOTATIONS_PRIVEES = %w(annotations_privees)
2017-08-30 15:31:36 +02:00
2017-05-26 21:32:43 +02:00
belongs_to :dossier
2017-09-27 12:14:41 +02:00
scope :unread, -> { where(already_read: false) }
scope :demande, -> { where(type_notif: DEMANDE) }
scope :avis, -> { where(type_notif: AVIS) }
scope :messagerie, -> { where(type_notif: MESSAGERIE) }
scope :annotations_privees, -> { where(type_notif: ANNOTATIONS_PRIVEES) }
2017-09-27 12:14:41 +02:00
scope :mark_as_read, -> { update_all(already_read: true) }
2017-08-30 15:31:36 +02:00
def demande?
Notification::DEMANDE.include?(type_notif)
end
2017-09-27 11:55:56 +02:00
def avis?
Notification::AVIS.include?(type_notif)
2017-08-30 15:31:36 +02:00
end
def messagerie?
Notification::MESSAGERIE.include?(type_notif)
end
def annotations_privees?
Notification::ANNOTATIONS_PRIVEES.include?(type_notif)
end
2016-12-21 17:26:31 +01:00
end