Skip to content

Commit

Permalink
add rna type de champ to harmonize api with rnf
Browse files Browse the repository at this point in the history
  • Loading branch information
lisa-durand committed Feb 7, 2024
1 parent d925130 commit 6ff07d0
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/graphql/api/v2/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def self.resolve_type(type_definition, object, ctx)
Types::Champs::DepartementChampType,
Types::Champs::DossierLinkChampType,
Types::Champs::EpciChampType,
Types::Champs::RNAChampType,
Types::Champs::RNFChampType,
Types::Champs::IntegerNumberChampType,
Types::Champs::LinkedDropDownListChampType,
Expand Down
29 changes: 29 additions & 0 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3620,6 +3620,35 @@ type Query {
): GroupeInstructeurWithDossiers!
}

type RNA {
address: Address
id: String!
title: String
}

type RNAChamp implements Champ {
commune: Commune
departement: Departement
id: ID!

"""
Libellé du champ.
"""
label: String!
prefilled: Boolean!
rna: RNA

"""
La valeur du champ sous forme texte.
"""
stringValue: String

"""
Date de dernière modification du champ.
"""
updatedAt: ISO8601DateTime!
}

type RNAChampDescriptor implements ChampDescriptor {
"""
Description des champs d’un bloc répétable.
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/types/champ_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def resolve_type(object, context)
Types::Champs::TitreIdentiteChampType
when ::Champs::EpciChamp
Types::Champs::EpciChampType
when ::Champs::RNAChamp
Types::Champs::RNAChampType
when ::Champs::RNFChamp
Types::Champs::RNFChampType
when ::Champs::EngagementJuridiqueChamp
Expand Down
23 changes: 23 additions & 0 deletions app/graphql/types/champs/rna_champ_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Types::Champs
class RNAChampType < Types::BaseObject
implements Types::ChampType

class RNAType < Types::BaseObject
field :id, String, null: false, method: :value
field :title, String, null: true, method: :title
field :address, Types::AddressType, null: true, method: :rna_address
end

field :rna, RNAType, null: true
field :commune, Types::Champs::CommuneChampType::CommuneType, null: true
field :departement, Types::Champs::DepartementChampType::DepartementType, null: true

def rna_id
object.value
end

def rna
object if object.value.present?
end
end
end
2 changes: 1 addition & 1 deletion app/lib/api_entreprise/rna_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def process_params
# see: https://mattermost.incubateur.net/betagouv/pl/r6txumw9cpyx58rt7iq5dte9qe
"association_date_declaration" => meta[:date_derniere_mise_a_jour_rna],
"association_date_publication" => data[:date_publication_journal_officiel],
"address" => data[:adresse_siege]
"adresse" => data[:adresse_siege]
}
end
end
Expand Down
26 changes: 21 additions & 5 deletions app/models/champs/rna_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ def title
data&.dig("association_titre")
end

def full_address
address = data&.dig("address")
"#{address["numero_voie"]} #{address["type_voie"]} #{address["libelle_voie"]} #{address["code_postal"]} #{address["commune"]}"
end

def identifier
title.present? ? "#{value} (#{title})" : value
end
Expand All @@ -27,4 +22,25 @@ def for_export
def search_terms
etablissement.present? ? etablissement.search_terms : [value]
end

def full_address
address = data&.dig("adresse")
return if address.blank?
"#{address["numero_voie"]} #{address["type_voie"]} #{address["libelle_voie"]} #{address["code_postal"]} #{address["commune"]}"
end

def rna_address
address = data&.dig("adresse")
return if address.blank?
{
label: full_address,
type: "housenumber",
street_address: address["libelle_voie"] ? [address["numero_voie"], address["type_voie"], address["libelle_voie"]].compact.join(' ') : nil,
street_number: address["numero_voie"],
street_name: [address["type_voie"], address["libelle_voie"]].compact.join(' '),
postal_code: address["code_postal"],
city_name: address["commune"],
city_code: address["code_insee"]
}
end
end
10 changes: 10 additions & 0 deletions spec/lib/api_entreprise/rna_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
expect(subject["association_objet"]).to eq("L'association a pour objet de promouvoir la pratique du sport de haut niveau et de contribuer à la formation des jeunes sportifs.")
expect(subject["association_date_declaration"]).to eq("2019-01-01")
expect(subject["association_date_publication"]).to eq("2018-01-01")
expect(subject["adresse"]).to eq({
complement: "",
numero_voie: "33",
type_voie: "rue",
libelle_voie: "de Modagor",
distribution: "dummy",
code_insee: "75108",
code_postal: "75009",
commune: "Paris"
})
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,17 @@
"association_date_creation" => "2015-01-01",
"association_date_declaration" => "2019-01-01",
"association_date_publication" => "2018-01-01",
"association_rna" => "W751080001"
"association_rna" => "W751080001",
"adresse" => {
"complement" => "",
"numero_voie" => "33",
"type_voie" => "rue",
"libelle_voie" => "de Modagor",
"distribution" => "dummy",
"code_insee" => "75108",
"code_postal" => "75009",
"commune" => "Paris"
}
}
end
end
Expand Down

0 comments on commit 6ff07d0

Please sign in to comment.