tech(refactor): extract states close to expiration within their scope.

This commit is contained in:
Martin 2021-11-19 14:07:47 +01:00
parent 1d721f14a0
commit d8257284ef

View file

@ -289,20 +289,35 @@ class Dossier < ApplicationRecord
.where.not(user_id: nil) .where.not(user_id: nil)
end end
scope :interval_brouillon_close_to_expiration, -> do
where("dossiers.created_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
end
scope :brouillon_close_to_expiration, -> do scope :brouillon_close_to_expiration, -> do
state_brouillon state_brouillon.joins(:procedure).interval_brouillon_close_to_expiration
.joins(:procedure) end
.where("dossiers.created_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
scope :interval_en_construction_close_to_expiration, -> do
where("dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
end end
scope :en_construction_close_to_expiration, -> do scope :en_construction_close_to_expiration, -> do
state_en_construction state_en_construction.joins(:procedure).interval_en_construction_close_to_expiration
.joins(:procedure) end
.where("dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
scope :interval_en_instruction_close_to_expiration, -> do
where("dossiers.en_instruction_at + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
end end
scope :en_instruction_close_to_expiration, -> do scope :en_instruction_close_to_expiration, -> do
state_en_instruction state_en_instruction.joins(:procedure).interval_en_instruction_close_to_expiration
end
scope :interval_termine_close_to_expiration, -> do
where(id: Traitement.termine_close_to_expiration.select(:dossier_id).distinct)
end
scope :termine_close_to_expiration, -> do
state_termine
.joins(:procedure) .joins(:procedure)
.where("dossiers.en_instruction_at + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION }) .interval_termine_close_to_expiration
end end
# TODO/MFO # TODO/MFO