Add dossier champs and annotations types

This commit is contained in:
Paul Chavard 2019-08-28 11:25:41 +02:00
parent 1c10718c11
commit eb7aba18e6
25 changed files with 454 additions and 3 deletions

View file

@ -31,6 +31,22 @@ class Api::V2::Schema < GraphQL::Schema
end
end
orphan_types Types::Champs::CarteChampType,
Types::Champs::CheckboxChampType,
Types::Champs::DateChampType,
Types::Champs::DecimalNumberChampType,
Types::Champs::DossierLinkChampType,
Types::Champs::IntegerNumberChampType,
Types::Champs::LinkedDropDownListChampType,
Types::Champs::MultipleDropDownListChampType,
Types::Champs::PieceJustificativeChampType,
Types::Champs::RepetitionChampType,
Types::Champs::SiretChampType,
Types::Champs::TextChampType,
Types::GeoAreas::ParcelleCadastraleType,
Types::GeoAreas::QuartierPrioritaireType,
Types::GeoAreas::SelectionUtilisateurType
def self.unauthorized_object(error)
# Add a top-level error to the response instead of returning nil:
raise GraphQL::ExecutionError.new("An object of type #{error.type.graphql_name} was hidden due to permissions", extensions: { code: :unauthorized })

View file

@ -6,6 +6,17 @@ type Avis {
updatedAt: ISO8601DateTime!
}
type CarteChamp implements Champ {
geoAreas: [GeoArea!]!
id: ID!
label: String!
}
interface Champ {
id: ID!
label: String!
}
type ChampInfo {
description: String
id: ID!
@ -14,6 +25,29 @@ type ChampInfo {
type: TypeDeChamp!
}
type CheckboxChamp implements Champ {
id: ID!
label: String!
value: Boolean!
}
"""
GeoJSON coordinates
"""
scalar Coordinates
type DateChamp implements Champ {
id: ID!
label: String!
value: ISO8601DateTime
}
type DecimalNumberChamp implements Champ {
id: ID!
label: String!
value: Float
}
"""
Une demarche
"""
@ -119,7 +153,9 @@ enum DemarcheState {
Un dossier
"""
type Dossier {
annotations: [Champ!]!
avis: [Avis!]!
champs: [Champ!]!
createdAt: ISO8601DateTime!
"""
@ -173,6 +209,12 @@ type DossierEdge {
node: Dossier
}
type DossierLinkChamp implements Champ {
dossier: Dossier
id: ID!
label: String!
}
enum DossierState {
"""
Accepté
@ -205,11 +247,50 @@ enum DossierState {
sans_suite
}
interface GeoArea {
geometry: GeoJSON!
id: ID
source: GeoAreaSource!
}
enum GeoAreaSource {
"""
translation missing: fr.activerecord.attributes.geo_area.source.cadastre
"""
cadastre
"""
translation missing: fr.activerecord.attributes.geo_area.source.parcelle_agricole
"""
parcelle_agricole
"""
translation missing: fr.activerecord.attributes.geo_area.source.quartier_prioritaire
"""
quartier_prioritaire
"""
translation missing: fr.activerecord.attributes.geo_area.source.selection_utilisateur
"""
selection_utilisateur
}
type GeoJSON {
coordinates: Coordinates!
type: String!
}
"""
An ISO 8601-encoded datetime
"""
scalar ISO8601DateTime
type IntegerNumberChamp implements Champ {
id: ID!
label: String!
value: Int
}
type Message {
attachment: URL
body: String!
@ -245,11 +326,56 @@ type PageInfo {
startCursor: String
}
type ParcelleCadastrale implements GeoArea {
codeArr: String!
codeCom: String!
codeDep: String!
feuille: Int!
geometry: GeoJSON!
id: ID
nomCom: String!
numero: String!
section: String!
source: GeoAreaSource!
surfaceIntersection: Float!
surfaceParcelle: Float!
}
type PersonneMorale {
adresse: String!
codeInseeLocalite: String!
codePostal: String!
complementAdresse: String!
libelleNaf: String!
localite: String!
naf: String!
nomVoie: String!
numeroVoie: String!
siegeSocial: String!
siret: String!
typeVoie: String!
}
type PieceJustificativeChamp implements Champ {
id: ID!
label: String!
url: URL
}
type Profile {
email: String!
id: ID!
}
type QuartierPrioritaire implements GeoArea {
code: String!
commune: String!
geometry: GeoJSON!
id: ID
nom: String!
source: GeoAreaSource!
}
type Query {
"""
Informations concernant une démarche.
@ -272,6 +398,30 @@ type Query {
): Dossier!
}
type RepetitionChamp implements Champ {
champs: [Champ!]!
id: ID!
label: String!
}
type SelectionUtilisateur implements GeoArea {
geometry: GeoJSON!
id: ID
source: GeoAreaSource!
}
type SiretChamp implements Champ {
etablissement: PersonneMorale
id: ID!
label: String!
}
type TextChamp implements Champ {
id: ID!
label: String!
value: String
}
enum TypeDeChamp {
"""
Adresse

View file

@ -0,0 +1,40 @@
module Types
module ChampType
include Types::BaseInterface
global_id_field :id
field :label, String, null: false, method: :libelle
field :string_value, String, null: true, method: :for_api_v2
definition_methods do
def resolve_type(object, context)
case object
when ::Champs::EngagementChamp, ::Champs::YesNoChamp, ::Champs::CheckboxChamp
Types::Champs::CheckboxChampType
when ::Champs::DateChamp, ::Champs::DatetimeChamp
Types::Champs::DateChampType
when ::Champs::DossierLinkChamp
Types::Champs::DossierLinkChampType
when ::Champs::PieceJustificativeChamp
Types::Champs::PieceJustificativeChampType
when ::Champs::CarteChamp
Types::Champs::CarteChampType
when ::Champs::NumberChamp, ::Champs::IntegerNumberChamp
Types::Champs::IntegerNumberChampType
when ::Champs::DecimalNumberChamp
Types::Champs::DecimalNumberChampType
when ::Champs::SiretChamp
Types::Champs::SiretChampType
when ::Champs::RepetitionChamp
Types::Champs::RepetitionChampType
when ::Champs::MultipleDropDownListChamp
Types::Champs::MultipleDropDownListChampType
when ::Champs::LinkedDropDownListChamp
Types::Champs::LinkedDropDownListChampType
else
Types::Champs::TextChampType
end
end
end
end
end

View file

@ -0,0 +1,11 @@
module Types::Champs
class CarteChampType < Types::BaseObject
implements Types::ChampType
field :geo_areas, [Types::GeoAreaType], null: false
def geo_areas
Loaders::Association.for(Champs::CarteChamp, :geo_areas).load(object)
end
end
end

View file

@ -0,0 +1,16 @@
module Types::Champs
class CheckboxChampType < Types::BaseObject
implements Types::ChampType
field :value, Boolean, null: false
def value
case object.value
when 'true', 'on', '1'
true
else
false
end
end
end
end

View file

@ -0,0 +1,13 @@
module Types::Champs
class DateChampType < Types::BaseObject
implements Types::ChampType
field :value, GraphQL::Types::ISO8601DateTime, null: true
def value
if object.value.present?
Time.zone.parse(object.value)
end
end
end
end

View file

@ -0,0 +1,13 @@
module Types::Champs
class DecimalNumberChampType < Types::BaseObject
implements Types::ChampType
field :value, Float, null: true
def value
if object.value.present?
object.value.to_f
end
end
end
end

View file

@ -0,0 +1,13 @@
module Types::Champs
class DossierLinkChampType < Types::BaseObject
implements Types::ChampType
field :dossier, Types::DossierType, null: true
def dossier
if object.value.present?
Loaders::Record.for(Dossier).load(object.value)
end
end
end
end

View file

@ -0,0 +1,13 @@
module Types::Champs
class IntegerNumberChampType < Types::BaseObject
implements Types::ChampType
field :value, Int, null: true
def value
if object.value.present?
object.value.to_i
end
end
end
end

View file

@ -0,0 +1,8 @@
module Types::Champs
class LinkedDropDownListChampType < Types::BaseObject
implements Types::ChampType
field :primary_value, String, null: true
field :secondary_value, String, null: true
end
end

View file

@ -0,0 +1,7 @@
module Types::Champs
class MultipleDropDownListChampType < Types::BaseObject
implements Types::ChampType
field :values, [String], null: false, method: :selected_options
end
end

View file

@ -0,0 +1,10 @@
module Types::Champs
class PieceJustificativeChampType < Types::BaseObject
include Rails.application.routes.url_helpers
implements Types::ChampType
field :url, Types::URL, null: true, extensions: [
{ Extensions::Attachment => { attachment: :piece_justificative_file } }
]
end
end

View file

@ -0,0 +1,11 @@
module Types::Champs
class RepetitionChampType < Types::BaseObject
implements Types::ChampType
field :champs, [Types::ChampType], null: false
def champs
Loaders::Association.for(object.class, :champs).load(object)
end
end
end

View file

@ -0,0 +1,13 @@
module Types::Champs
class SiretChampType < Types::BaseObject
implements Types::ChampType
field :etablissement, Types::PersonneMoraleType, null: true
def etablissement
if object.etablissement_id.present?
Loaders::Record.for(Etablissement).load(object.etablissement_id)
end
end
end
end

View file

@ -0,0 +1,7 @@
module Types::Champs
class TextChampType < Types::BaseObject
implements Types::ChampType
field :value, String, null: true
end
end

View file

@ -27,6 +27,9 @@ module Types
field :usager, Types::ProfileType, null: false
field :instructeurs, [Types::ProfileType], null: false
field :champs, [Types::ChampType], null: false
field :annotations, [Types::ChampType], null: false
field :messages, [Types::MessageType], null: false
field :avis, [Types::AvisType], null: false
@ -50,6 +53,14 @@ module Types
Loaders::Association.for(object.class, avis: [:instructeur, :claimant]).load(object)
end
def champs
Loaders::Association.for(object.class, :champs).load(object)
end
def annotations
Loaders::Association.for(object.class, :champs_private).load(object)
end
def self.authorized?(object, context)
authorized_demarche?(object.procedure, context)
end

View file

@ -0,0 +1,30 @@
module Types
module GeoAreaType
include Types::BaseInterface
class GeoAreaSource < Types::BaseEnum
GeoArea.sources.each do |symbol_name, string_name|
value(string_name,
I18n.t(symbol_name, scope: [:activerecord, :attributes, :geo_area, :source]),
value: symbol_name)
end
end
global_id_field :id
field :source, GeoAreaSource, null: false
field :geometry, Types::GeoJSON, null: false
definition_methods do
def resolve_type(object, context)
case object.source
when GeoArea.sources.fetch(:cadastre)
Types::GeoAreas::ParcelleCadastraleType
when GeoArea.sources.fetch(:quartier_prioritaire)
Types::GeoAreas::QuartierPrioritaireType
when GeoArea.sources.fetch(:selection_utilisateur)
Types::GeoAreas::SelectionUtilisateurType
end
end
end
end
end

View file

@ -0,0 +1,15 @@
module Types::GeoAreas
class ParcelleCadastraleType < Types::BaseObject
implements Types::GeoAreaType
field :surface_intersection, Float, null: false
field :surface_parcelle, Float, null: false
field :numero, String, null: false
field :feuille, Int, null: false
field :section, String, null: false
field :code_dep, String, null: false
field :nom_com, String, null: false
field :code_com, String, null: false
field :code_arr, String, null: false
end
end

View file

@ -0,0 +1,9 @@
module Types::GeoAreas
class QuartierPrioritaireType < Types::BaseObject
implements Types::GeoAreaType
field :code, String, null: false
field :nom, String, null: false
field :commune, String, null: false
end
end

View file

@ -0,0 +1,5 @@
module Types::GeoAreas
class SelectionUtilisateurType < Types::BaseObject
implements Types::GeoAreaType
end
end

View file

@ -0,0 +1,14 @@
module Types
class GeoJSON < Types::BaseObject
class CoordinatesType < Types::BaseScalar
description "GeoJSON coordinates"
def self.coerce_result(ruby_value, context)
ruby_value
end
end
field :type, String, null: false
field :coordinates, CoordinatesType, null: false
end
end

View file

@ -0,0 +1,16 @@
module Types
class PersonneMoraleType < Types::BaseObject
field :siret, String, null: false
field :siege_social, String, null: false
field :naf, String, null: false
field :libelle_naf, String, null: false
field :adresse, String, null: false
field :numero_voie, String, null: false
field :type_voie, String, null: false
field :nom_voie, String, null: false
field :complement_adresse, String, null: false
field :code_postal, String, null: false
field :localite, String, null: false
field :code_insee_localite, String, null: false
end
end

View file

@ -54,6 +54,10 @@ class Champ < ApplicationRecord
value
end
def for_api_v2
to_s
end
def for_tag
value.present? ? value.to_s : ''
end
@ -62,6 +66,10 @@ class Champ < ApplicationRecord
:value
end
def to_typed_id
type_de_champ.to_typed_id
end
private
def needs_dossier_id?

View file

@ -21,6 +21,10 @@ class Champs::YesNoChamp < Champ
value == 'true'
end
def for_api_v2
true? ? 'true' : 'false'
end
private
def processed_value

View file

@ -163,9 +163,7 @@ class Dossier < ApplicationRecord
}
scope :for_procedure, -> (procedure) { includes(:user, :groupe_instructeur).where(groupe_instructeurs: { procedure: procedure }) }
scope :for_api_v2, -> {
includes(procedure: [:administrateurs], etablissement: [], individual: [])
}
scope :for_api_v2, -> { includes(procedure: [:administrateurs], etablissement: [], individual: []) }
accepts_nested_attributes_for :individual