refactor(dossier): use touch

This commit is contained in:
Paul Chavard 2024-11-13 21:47:36 +01:00
parent 7932085976
commit c2c26719d3
No known key found for this signature in database
4 changed files with 12 additions and 6 deletions

View file

@ -30,8 +30,14 @@ class Champs::PieceJustificativeController < Champs::ChampController
save_succeed = @champ.save
end
@champ.dossier.update(last_champ_updated_at: Time.zone.now.utc) if save_succeed
if save_succeed && dossier.brouillon?
dossier.touch(:last_champ_updated_at, :last_champ_piece_jointe_updated_at)
end
save_succeed
end
def dossier
@champ.dossier
end
end

View file

@ -57,7 +57,7 @@ module CreateAvisConcern
persisted, failed = create_results.partition(&:persisted?)
if persisted.any?
dossier.update!(last_avis_updated_at: Time.zone.now)
dossier.touch(:last_avis_updated_at)
sent_emails_addresses = []
persisted.each do |avis|
avis.dossier.demander_un_avis!(avis)

View file

@ -250,7 +250,7 @@ module Instructeurs
if commentaire.valid?
dossier.flag_as_pending_correction!(commentaire, params[:reason].presence)
dossier.update!(last_commentaire_updated_at: Time.zone.now)
dossier.touch(:last_commentaire_updated_at)
current_instructeur.follow(dossier)
flash.notice = "Dossier marqué comme en attente de correction."
@ -275,7 +275,7 @@ module Instructeurs
@commentaire = CommentaireService.create(current_instructeur, dossier, commentaire_params)
if @commentaire.errors.empty?
@commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now)
@commentaire.dossier.touch(:last_commentaire_updated_at)
current_instructeur.follow(dossier)
flash.notice = "Message envoyé"
redirect_to messagerie_instructeur_dossier_path(procedure, dossier)
@ -300,7 +300,7 @@ module Instructeurs
def update_annotations
dossier_with_champs.update_champs_attributes(champs_private_attributes_params, :private, updated_by: current_user.email)
if dossier.champs.any?(&:changed_for_autosave?)
dossier.last_champ_private_updated_at = Time.zone.now
dossier.touch(:last_champ_private_updated_at)
end
dossier.save(context: :champs_private_value)

View file

@ -237,7 +237,7 @@ module Instructeurs
dossiers.each do |dossier|
commentaire = CommentaireService.create(current_instructeur, dossier, bulk_message_params.except(:targets))
if commentaire.errors.empty?
commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now)
commentaire.dossier.touch(:last_commentaire_updated_at)
else
errors << dossier.id
end