add default values when nil

This commit is contained in:
clemkeirua 2020-09-21 21:16:58 +02:00
parent adb2a91640
commit 1173f1e459
2 changed files with 12 additions and 2 deletions

View file

@ -14,7 +14,7 @@ module Types
field :nom_commercial, String, null: false
field :raison_sociale, String, null: false
field :siret_siege_social, String, null: false
field :code_effectif_entreprise, String, null: false
field :code_effectif_entreprise, String, null: true
field :effectif_mensuel, EffectifType, null: true, description: "effectif pour un mois donné"
field :effectif_annuel, EffectifType, null: true, description: "effectif moyen d'une année"
field :date_creation, GraphQL::Types::ISO8601Date, null: false
@ -41,6 +41,16 @@ module Types
end
end
def capital_social
# capital_social is defined as a BigInt, so we can't return an empty string when value is unknown
# 0 could appear to be a legitimate value, so a negative value helps to ensure the value is not known
object.capital_social || '-1'
end
def code_effectif_entreprise
object.code_effectif_entreprise || ''
end
def effectif_annuel
if object.effectif_annuel.present?
{

View file

@ -453,7 +453,7 @@ describe API::V2::GraphqlController do
entreprise: {
siren: dossier.etablissement.entreprise_siren,
dateCreation: dossier.etablissement.entreprise_date_creation.iso8601,
capitalSocial: '',
capitalSocial: '-1',
codeEffectifEntreprise: ''
}
}