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 ||=
|
|
|
|
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
|
|
|
|
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
|
|
|
|
when 'commentaire'
|
|
|
|
"#{notification.liste.size + 1} nouveau(x) commentaire(s) déposé(s)."
|
2016-12-26 11:33:12 +01:00
|
|
|
when 'cerfa'
|
|
|
|
"Un nouveau formulaire a été déposé."
|
2016-12-26 11:42:02 +01:00
|
|
|
when 'piece_justificative'
|
|
|
|
attribut
|
2016-12-26 11:47:51 +01:00
|
|
|
when 'champs'
|
|
|
|
attribut
|
2016-12-26 11:57:08 +01:00
|
|
|
when 'submitted'
|
|
|
|
"Le dossier n°#{@dossier_id} a été déposé."
|
2016-12-22 20:40:23 +01:00
|
|
|
else
|
|
|
|
'Notification par défaut'
|
|
|
|
end
|
|
|
|
end
|
2016-12-26 17:18:45 +01:00
|
|
|
end
|