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',
|
|
|
|
avis: 'avis'
|
|
|
|
}
|
|
|
|
|
2017-08-30 15:31:36 +02:00
|
|
|
DEMANDE = %w(cerfa piece_justificative champs submitted)
|
|
|
|
INSTRUCTION = %w(avis)
|
|
|
|
MESSAGERIE = %w(commentaire)
|
|
|
|
|
2017-05-26 21:32:43 +02:00
|
|
|
belongs_to :dossier
|
|
|
|
|
2017-08-30 15:31:36 +02:00
|
|
|
scope :unread, -> { where(already_read: false) }
|
|
|
|
scope :demande, -> { where(type_notif: DEMANDE) }
|
|
|
|
scope :instruction, -> { where(type_notif: INSTRUCTION) }
|
|
|
|
scope :messagerie, -> { where(type_notif: MESSAGERIE) }
|
|
|
|
scope :mark_as_read, -> { update_all(already_read: true) }
|
|
|
|
|
|
|
|
def demande?
|
|
|
|
Notification::DEMANDE.include?(type_notif)
|
|
|
|
end
|
|
|
|
|
|
|
|
def instruction?
|
|
|
|
Notification::INSTRUCTION.include?(type_notif)
|
|
|
|
end
|
|
|
|
|
|
|
|
def messagerie?
|
|
|
|
Notification::MESSAGERIE.include?(type_notif)
|
|
|
|
end
|
2016-12-21 17:26:31 +01:00
|
|
|
end
|