Merge pull request #2766 from betagouv/2759-followup

#2759 follow-up
This commit is contained in:
gregoirenovel 2018-10-05 00:01:27 +02:00 committed by GitHub
commit 0d7197392a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -10,7 +10,7 @@ class ApiEntreprise::ExercicesAdapter < ApiEntreprise::Adapter
exercice.slice(*attr_to_fetch) exercice.slice(*attr_to_fetch)
end end
if exercices_array == exercices_array.select { |params| valid_params?(params) } if exercices_array.all? { |params| valid_params?(params) }
{ exercices_attributes: exercices_array } { exercices_attributes: exercices_array }
else else
{} {}

View file

@ -6,17 +6,20 @@ class ApiEntreprise::RNAAdapter < ApiEntreprise::Adapter
end end
def process_params def process_params
# Responses with a 206 codes are sometimes not useable, # Sometimes the associations endpoints responses with a 206,
# as the RNA calls often return a 206 with an error message, # and these response are often useable as the they only
# not a partial response # contain an error message.
# Therefore here we make sure that our response seems valid
# by checking that there is an association attribute.
if !data_source.key?(:association) if !data_source.key?(:association)
{} {}
else else
association_id = data_source[:association][:id]
params = data_source[:association].slice(*attr_to_fetch) params = data_source[:association].slice(*attr_to_fetch)
if params[:id].present? && valid_params?(params) if association_id.present? && valid_params?(params)
params[:rna] = params[:id] params[:rna] = association_id
params.except(:id).transform_keys { |k| :"association_#{k}" } params.transform_keys { |k| :"association_#{k}" }
else else
{} {}
end end
@ -25,7 +28,6 @@ class ApiEntreprise::RNAAdapter < ApiEntreprise::Adapter
def attr_to_fetch def attr_to_fetch
[ [
:id,
:titre, :titre,
:objet, :objet,
:date_creation, :date_creation,