feat(API): cast type de champ EJ in a dedicated graphql type
This commit is contained in:
parent
e52bd9d6bf
commit
989a7ba787
6 changed files with 110 additions and 1 deletions
|
@ -74,6 +74,7 @@ class API::V2::Schema < GraphQL::Schema
|
|||
Types::Champs::SiretChampType,
|
||||
Types::Champs::TextChampType,
|
||||
Types::Champs::TitreIdentiteChampType,
|
||||
Types::Champs::EngagementJuridiqueChampType,
|
||||
Types::GeoAreas::ParcelleCadastraleType,
|
||||
Types::GeoAreas::SelectionUtilisateurType,
|
||||
Types::PersonneMoraleType,
|
||||
|
@ -118,7 +119,7 @@ class API::V2::Schema < GraphQL::Schema
|
|||
Types::Champs::Descriptor::TitreIdentiteChampDescriptorType,
|
||||
Types::Champs::Descriptor::YesNoChampDescriptorType,
|
||||
Types::Champs::Descriptor::ExpressionReguliereChampDescriptorType,
|
||||
Types::Champs::Descriptor::EngagementJuridiqueChampDescriptorType
|
||||
Types::Champs::Descriptor::EngagementJuridiqueChampDescriptorType
|
||||
|
||||
def self.unauthorized_object(error)
|
||||
# Add a top-level error to the response instead of returning nil:
|
||||
|
|
|
@ -574,6 +574,11 @@ class API::V2::StoredQuery
|
|||
...RNFFragment
|
||||
}
|
||||
}
|
||||
... on EngagementJuridiqueChamp {
|
||||
engagementJuridique {
|
||||
...EngagementJuridiqueFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment PersonneMoraleFragment on PersonneMorale {
|
||||
|
@ -684,6 +689,11 @@ class API::V2::StoredQuery
|
|||
}
|
||||
}
|
||||
|
||||
fragment EngagementJuridiqueFragment on EngagementJuridique {
|
||||
montantEngage
|
||||
montantPaye
|
||||
}
|
||||
|
||||
fragment PageInfoFragment on PageInfo {
|
||||
hasPreviousPage
|
||||
hasNextPage
|
||||
|
|
|
@ -2203,6 +2203,35 @@ type EmailChampDescriptor implements ChampDescriptor {
|
|||
type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.")
|
||||
}
|
||||
|
||||
type EngagementJuridique {
|
||||
montantEngage: String
|
||||
montantPaye: String
|
||||
}
|
||||
|
||||
type EngagementJuridiqueChamp implements Champ {
|
||||
"""
|
||||
Montant engagé et payé de l'EJ.
|
||||
"""
|
||||
engagementJuridique: EngagementJuridique
|
||||
id: ID!
|
||||
|
||||
"""
|
||||
Libellé du champ.
|
||||
"""
|
||||
label: String!
|
||||
prefilled: Boolean!
|
||||
|
||||
"""
|
||||
La valeur du champ sous forme texte.
|
||||
"""
|
||||
stringValue: String
|
||||
|
||||
"""
|
||||
Date de dernière modification du champ.
|
||||
"""
|
||||
updatedAt: ISO8601DateTime!
|
||||
}
|
||||
|
||||
type EngagementJuridiqueChampDescriptor implements ChampDescriptor {
|
||||
"""
|
||||
Description des champs d’un bloc répétable.
|
||||
|
|
|
@ -77,6 +77,8 @@ module Types
|
|||
Types::Champs::EpciChampType
|
||||
when ::Champs::RNFChamp
|
||||
Types::Champs::RNFChampType
|
||||
when ::Champs::EngagementJuridiqueChamp
|
||||
Types::Champs::EngagementJuridiqueChampType
|
||||
else
|
||||
Types::Champs::TextChampType
|
||||
end
|
||||
|
|
28
app/graphql/types/champs/engagement_juridique_champ_type.rb
Normal file
28
app/graphql/types/champs/engagement_juridique_champ_type.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Types::Champs
|
||||
class EngagementJuridiqueChampType < Types::BaseObject
|
||||
implements Types::ChampType
|
||||
|
||||
class EngagementJuridiqueType < Types::BaseObject
|
||||
field :montant_engage, String, null: true
|
||||
field :montant_paye, String, null: true
|
||||
|
||||
def numero
|
||||
object.value
|
||||
end
|
||||
|
||||
def montant_engage
|
||||
"NotYetImplemented"
|
||||
end
|
||||
|
||||
def montant_paye
|
||||
"NotYetImplemented"
|
||||
end
|
||||
end
|
||||
|
||||
field :engagement_juridique, EngagementJuridiqueType, "Montant engagé et payé de l'EJ.", null: true
|
||||
|
||||
def engagement_juridique
|
||||
object if object.value.present?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -75,6 +75,17 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'dossier with annotations' do
|
||||
let(:procedure) { create(:procedure, :published, types_de_champ_private: [{ type: :engagement_juridique }]) }
|
||||
let(:dossier) { create(:dossier, :accepte, :with_populated_champs, procedure: procedure) }
|
||||
let(:query) { DOSSIER_WITH_ANNOTATIONS_QUERY }
|
||||
let(:variables) { { number: dossier.id } }
|
||||
|
||||
it do
|
||||
expect(data[:dossier][:annotations][0][:__typename]).to eq "EngagementJuridiqueChamp"
|
||||
end
|
||||
end
|
||||
|
||||
describe 'dossier with selected champ' do
|
||||
let(:procedure) { create(:procedure, types_de_champ_public: [{ libelle: 'yolo' }, { libelle: 'toto' }]) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:) }
|
||||
|
@ -324,7 +335,35 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
}
|
||||
}
|
||||
GRAPHQL
|
||||
DOSSIER_WITH_ANNOTATIONS_QUERY = <<-GRAPHQL
|
||||
query($number: Int!) {
|
||||
dossier(number: $number) {
|
||||
id
|
||||
number
|
||||
revision {
|
||||
champDescriptors {
|
||||
id
|
||||
label
|
||||
}
|
||||
}
|
||||
annotations {
|
||||
id
|
||||
label
|
||||
__typename
|
||||
... on EngagementJuridiqueChamp {
|
||||
engagementJuridique {
|
||||
...EngagementJuridiqueFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fragment EngagementJuridiqueFragment on EngagementJuridique {
|
||||
montantEngage
|
||||
montantPaye
|
||||
}
|
||||
|
||||
GRAPHQL
|
||||
DOSSIER_WITH_CHAMPS_QUERY = <<-GRAPHQL
|
||||
query($number: Int!) {
|
||||
dossier(number: $number) {
|
||||
|
|
Loading…
Reference in a new issue