Merge pull request #8323 from tchak/fix-graphql-champs
feat(graphql): add pays champ to API
This commit is contained in:
commit
62813f3d74
6 changed files with 53 additions and 6 deletions
|
@ -59,6 +59,7 @@ class API::V2::Schema < GraphQL::Schema
|
||||||
Types::Champs::IntegerNumberChampType,
|
Types::Champs::IntegerNumberChampType,
|
||||||
Types::Champs::LinkedDropDownListChampType,
|
Types::Champs::LinkedDropDownListChampType,
|
||||||
Types::Champs::MultipleDropDownListChampType,
|
Types::Champs::MultipleDropDownListChampType,
|
||||||
|
Types::Champs::PaysChampType,
|
||||||
Types::Champs::PieceJustificativeChampType,
|
Types::Champs::PieceJustificativeChampType,
|
||||||
Types::Champs::RegionChampType,
|
Types::Champs::RegionChampType,
|
||||||
Types::Champs::RepetitionChampType,
|
Types::Champs::RepetitionChampType,
|
||||||
|
|
|
@ -454,6 +454,12 @@ class API::V2::StoredQuery
|
||||||
code
|
code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
... on PaysChamp {
|
||||||
|
pays {
|
||||||
|
name
|
||||||
|
code
|
||||||
|
}
|
||||||
|
}
|
||||||
... on SiretChamp {
|
... on SiretChamp {
|
||||||
etablissement {
|
etablissement {
|
||||||
...PersonneMoraleFragment
|
...PersonneMoraleFragment
|
||||||
|
|
|
@ -2017,6 +2017,26 @@ type ParcelleCadastrale implements GeoArea {
|
||||||
surfaceParcelle: Float! @deprecated(reason: "Utilisez le champ `surface` à la place.")
|
surfaceParcelle: Float! @deprecated(reason: "Utilisez le champ `surface` à la place.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Pays {
|
||||||
|
code: String!
|
||||||
|
name: String!
|
||||||
|
}
|
||||||
|
|
||||||
|
type PaysChamp implements Champ {
|
||||||
|
id: ID!
|
||||||
|
|
||||||
|
"""
|
||||||
|
Libellé du champ.
|
||||||
|
"""
|
||||||
|
label: String!
|
||||||
|
pays: Pays
|
||||||
|
|
||||||
|
"""
|
||||||
|
La valeur du champ sous forme texte.
|
||||||
|
"""
|
||||||
|
stringValue: String
|
||||||
|
}
|
||||||
|
|
||||||
type PersonneMorale implements Demandeur {
|
type PersonneMorale implements Demandeur {
|
||||||
address: Address!
|
address: Address!
|
||||||
adresse: String! @deprecated(reason: "Utilisez le champ `address.label` à la place.")
|
adresse: String! @deprecated(reason: "Utilisez le champ `address.label` à la place.")
|
||||||
|
|
|
@ -43,6 +43,12 @@ module Types
|
||||||
else
|
else
|
||||||
Types::Champs::TextChampType
|
Types::Champs::TextChampType
|
||||||
end
|
end
|
||||||
|
when ::Champs::PaysChamp
|
||||||
|
if context.has_fragment?(:PaysChamp)
|
||||||
|
Types::Champs::PaysChampType
|
||||||
|
else
|
||||||
|
Types::Champs::TextChampType
|
||||||
|
end
|
||||||
when ::Champs::DossierLinkChamp
|
when ::Champs::DossierLinkChamp
|
||||||
Types::Champs::DossierLinkChampType
|
Types::Champs::DossierLinkChampType
|
||||||
when ::Champs::PieceJustificativeChamp
|
when ::Champs::PieceJustificativeChamp
|
||||||
|
|
16
app/graphql/types/champs/pays_champ_type.rb
Normal file
16
app/graphql/types/champs/pays_champ_type.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
module Types::Champs
|
||||||
|
class PaysChampType < Types::BaseObject
|
||||||
|
implements Types::ChampType
|
||||||
|
|
||||||
|
class PaysType < Types::BaseObject
|
||||||
|
field :name, String, null: false
|
||||||
|
field :code, String, null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
field :pays, PaysType, null: true
|
||||||
|
|
||||||
|
def pays
|
||||||
|
object if object.external_id.present?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -22,15 +22,15 @@
|
||||||
#
|
#
|
||||||
class Champs::PaysChamp < Champs::TextChamp
|
class Champs::PaysChamp < Champs::TextChamp
|
||||||
def for_export
|
def for_export
|
||||||
[formatted_value, code]
|
[name, code]
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
formatted_value
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
def for_tag
|
def for_tag
|
||||||
formatted_value
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
def selected
|
def selected
|
||||||
|
@ -54,9 +54,7 @@ class Champs::PaysChamp < Champs::TextChamp
|
||||||
external_id || APIGeoService.country_code(value)
|
external_id || APIGeoService.country_code(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def name
|
||||||
|
|
||||||
def formatted_value
|
|
||||||
if external_id
|
if external_id
|
||||||
APIGeoService.country_name(external_id)
|
APIGeoService.country_name(external_id)
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue