ba4ee68019
It’s the right way to contract “numéro” We should use the superscript lowercase o but it’s hard to do in places where only raw text is available
42 lines
1.1 KiB
Ruby
42 lines
1.1 KiB
Ruby
class NotificationService
|
|
|
|
def initialize type_notif, dossier_id, attribut_change=''
|
|
@type_notif = type_notif
|
|
@dossier_id = dossier_id
|
|
|
|
notification.liste.push text_for_notif attribut_change
|
|
notification.liste = notification.liste.uniq
|
|
|
|
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
|
|
|
|
def text_for_notif attribut=''
|
|
case @type_notif
|
|
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é."
|
|
else
|
|
'Notification par défaut'
|
|
end
|
|
end
|
|
end
|