feat(graphql): add commune and departement information to API
This commit is contained in:
parent
fcbe364ac8
commit
0036933425
5 changed files with 73 additions and 1 deletions
|
@ -43,6 +43,7 @@ class API::V2::Schema < GraphQL::Schema
|
|||
Types::Champs::CarteChampType,
|
||||
Types::Champs::CheckboxChampType,
|
||||
Types::Champs::CiviliteChampType,
|
||||
Types::Champs::CommuneChampType,
|
||||
Types::Champs::DateChampType,
|
||||
Types::Champs::DatetimeChampType,
|
||||
Types::Champs::DecimalNumberChampType,
|
||||
|
|
|
@ -233,6 +233,30 @@ type CiviliteChamp implements Champ {
|
|||
value: Civilite
|
||||
}
|
||||
|
||||
type Commune {
|
||||
"""
|
||||
Le code INSEE
|
||||
"""
|
||||
code: String!
|
||||
name: String!
|
||||
}
|
||||
|
||||
type CommuneChamp implements Champ {
|
||||
commune: Commune
|
||||
departement: Departement
|
||||
id: ID!
|
||||
|
||||
"""
|
||||
Libellé du champ.
|
||||
"""
|
||||
label: String!
|
||||
|
||||
"""
|
||||
La valeur du champ sous forme texte.
|
||||
"""
|
||||
stringValue: String
|
||||
}
|
||||
|
||||
"""
|
||||
GeoJSON coordinates
|
||||
"""
|
||||
|
@ -649,6 +673,11 @@ enum DemarcheState {
|
|||
publiee
|
||||
}
|
||||
|
||||
type Departement {
|
||||
code: String!
|
||||
name: String!
|
||||
}
|
||||
|
||||
"""
|
||||
Represents direct upload credentials
|
||||
"""
|
||||
|
|
|
@ -25,6 +25,12 @@ module Types
|
|||
else
|
||||
Types::Champs::DateChampType
|
||||
end
|
||||
when ::Champs::CommuneChamp
|
||||
if context.has_fragment?(:CommuneChamp)
|
||||
Types::Champs::CommuneChampType
|
||||
else
|
||||
Types::Champs::TextChampType
|
||||
end
|
||||
when ::Champs::DossierLinkChamp
|
||||
Types::Champs::DossierLinkChampType
|
||||
when ::Champs::PieceJustificativeChamp
|
||||
|
|
36
app/graphql/types/champs/commune_champ_type.rb
Normal file
36
app/graphql/types/champs/commune_champ_type.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Types::Champs
|
||||
class CommuneChampType < Types::BaseObject
|
||||
implements Types::ChampType
|
||||
|
||||
class CommuneType < Types::BaseObject
|
||||
field :name, String, null: false
|
||||
field :code, String, "Le code INSEE", null: false
|
||||
end
|
||||
|
||||
class DepartementType < Types::BaseObject
|
||||
field :name, String, null: false
|
||||
field :code, String, null: false
|
||||
end
|
||||
|
||||
field :commune, CommuneType, null: true
|
||||
field :departement, DepartementType, null: true
|
||||
|
||||
def commune
|
||||
if object.code?
|
||||
{
|
||||
name: object.to_s,
|
||||
code: object.code
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def departement
|
||||
if object.departement?
|
||||
{
|
||||
name: object.name_departement,
|
||||
code: object.code_departement
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -27,7 +27,7 @@ class Champs::CommuneChamp < Champs::TextChamp
|
|||
end
|
||||
|
||||
def name_departement
|
||||
#FIXME we originaly saved already formatted departement with the code in the name
|
||||
# FIXME we originaly saved already formatted departement with the code in the name
|
||||
departement&.gsub(/^(.[0-9])\s-\s/, '')
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue