2021-01-14 17:29:57 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: champs
|
|
|
|
#
|
2021-02-04 19:23:40 +01:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# data :jsonb
|
|
|
|
# fetch_external_data_exceptions :string is an Array
|
|
|
|
# private :boolean default(FALSE), not null
|
|
|
|
# row :integer
|
|
|
|
# type :string
|
|
|
|
# value :string
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# dossier_id :integer
|
|
|
|
# etablissement_id :integer
|
|
|
|
# external_id :string
|
|
|
|
# parent_id :bigint
|
|
|
|
# type_de_champ_id :integer
|
2021-01-14 17:29:57 +01:00
|
|
|
#
|
|
|
|
class Champs::AnnuaireEducationChamp < Champs::TextChamp
|
|
|
|
before_save :cleanup_if_empty
|
|
|
|
after_update_commit :fetch_data
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def cleanup_if_empty
|
2021-01-14 23:55:34 +01:00
|
|
|
if external_id_changed?
|
2021-01-14 17:29:57 +01:00
|
|
|
self.data = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_data
|
2021-01-14 23:55:34 +01:00
|
|
|
if external_id.present? && data.nil?
|
2021-01-14 17:29:57 +01:00
|
|
|
AnnuaireEducationUpdateJob.perform_later(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|