2016-12-21 17:26:31 +01:00
|
|
|
class Notification < ActiveRecord::Base
|
2016-12-22 20:40:23 +01:00
|
|
|
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)
|
|
|
|
|
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) }
|
|
|
|
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
|
2016-12-21 17:26:31 +01:00
|
|
|
end
|