2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-06 13:44:29 +01:00
|
|
|
class Follow < ApplicationRecord
|
2020-07-20 16:46:26 +02:00
|
|
|
belongs_to :instructeur, optional: false
|
2024-10-03 13:13:07 +02:00
|
|
|
belongs_to :dossier, optional: false, touch: true
|
2016-07-18 18:24:29 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
validates :instructeur_id, uniqueness: { scope: [:dossier_id, :unfollowed_at] }
|
2017-10-23 10:25:07 +02:00
|
|
|
|
|
|
|
before_create :set_default_date
|
|
|
|
|
2019-06-07 14:59:49 +02:00
|
|
|
scope :active, -> { where(unfollowed_at: nil) }
|
2019-06-07 14:59:49 +02:00
|
|
|
scope :inactive, -> { where.not(unfollowed_at: nil) }
|
2019-06-07 14:59:49 +02:00
|
|
|
|
2017-10-23 10:25:07 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_default_date
|
2018-10-25 15:07:15 +02:00
|
|
|
self.demande_seen_at ||= Time.zone.now
|
|
|
|
self.annotations_privees_seen_at ||= Time.zone.now
|
|
|
|
self.avis_seen_at ||= Time.zone.now
|
|
|
|
self.messagerie_seen_at ||= Time.zone.now
|
2017-10-23 10:25:07 +02:00
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|