2016-12-22 20:40:23 +01:00
|
|
|
|
class NotificationService
|
2016-12-26 11:42:02 +01:00
|
|
|
|
def initialize type_notif, dossier_id, attribut_change=''
|
2016-12-22 20:40:23 +01:00
|
|
|
|
@type_notif = type_notif
|
|
|
|
|
@dossier_id = dossier_id
|
|
|
|
|
|
2016-12-26 11:42:02 +01:00
|
|
|
|
notification.liste.push text_for_notif attribut_change
|
|
|
|
|
notification.liste = notification.liste.uniq
|
2016-12-22 20:40:23 +01:00
|
|
|
|
|
|
|
|
|
self
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def notify
|
|
|
|
|
notification.save
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def notification
|
|
|
|
|
@notification ||=
|
2018-01-15 18:56:00 +01:00
|
|
|
|
begin
|
|
|
|
|
Notification.find_by! dossier_id: @dossier_id, already_read: false, type_notif: @type_notif
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
Notification.new dossier_id: @dossier_id, type_notif: @type_notif, liste: []
|
|
|
|
|
end
|
2016-12-22 20:40:23 +01:00
|
|
|
|
end
|
|
|
|
|
|
2016-12-26 11:42:02 +01:00
|
|
|
|
def text_for_notif attribut=''
|
2016-12-22 20:40:23 +01:00
|
|
|
|
case @type_notif
|
2017-06-12 15:05:46 +02:00
|
|
|
|
when 'commentaire'
|
|
|
|
|
"#{notification.liste.size + 1} nouveau(x) commentaire(s) déposé(s)."
|
|
|
|
|
when 'cerfa'
|
|
|
|
|
"Un nouveau formulaire a été déposé."
|
|
|
|
|
when 'piece_justificative'
|
|
|
|
|
attribut
|
|
|
|
|
when 'champs'
|
|
|
|
|
attribut
|
|
|
|
|
when 'submitted'
|
|
|
|
|
"Le dossier nº #{@dossier_id} a été déposé."
|
|
|
|
|
when 'avis'
|
|
|
|
|
'Un nouvel avis a été rendu'
|
|
|
|
|
else
|
|
|
|
|
'Notification par défaut'
|
2016-12-22 20:40:23 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2016-12-26 17:18:45 +01:00
|
|
|
|
end
|