demarches-normaliennes/app/models/champs/cnaf_champ.rb
Martin 85a588541b feat(dossier_submitted_message): add a new system to customize the standby page (/merci) after an user created his folder. this is a basic feature that will come with more options asap
wip(dossier_created_hook): add tile to administrateurs/procedure#show in order to crud dossier_created_hook

refactor(css.utilities): remove merge helpers.scss within utils.scss (same purpose). use scss each for spacer modifiers

refactor(dossiers/_merci.html): extract partial _merci so we can re-use it in preview of dossier_created_hook.

feat(wip): current progress
2022-02-25 14:01:18 +01:00

53 lines
1.8 KiB
Ruby

# == Schema Information
#
# Table name: champs
#
# id :integer not null, primary key
# data :jsonb
# fetch_external_data_exceptions :string is an Array
# private :boolean default(FALSE), not null
# rebased_at :datetime
# row :integer
# type :string
# value :string
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer
#
class Champs::CnafChamp < Champs::TextChamp
# see https://github.com/betagouv/api-particulier/blob/master/src/presentation/middlewares/cnaf-input-validation.middleware.ts
validates :numero_allocataire, format: { with: /\A\d{1,7}\z/ }, if: -> { code_postal.present? && validation_context != :brouillon }
validates :code_postal, format: { with: /\A\w{5}\z/ }, if: -> { numero_allocataire.present? && validation_context != :brouillon }
store_accessor :value_json, :numero_allocataire, :code_postal
def blank?
external_id.nil?
end
def fetch_external_data?
true
end
def fetch_external_data
if valid?
APIParticulier::CnafAdapter.new(
procedure.api_particulier_token,
numero_allocataire,
code_postal,
procedure.api_particulier_sources
).to_params
end
end
def external_id
if numero_allocataire.present? && code_postal.present?
{ code_postal: code_postal, numero_allocataire: numero_allocataire }.to_json
end
end
end