From 1165f8483d798d800ab13491627216c5d857fc01 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 21 Apr 2020 20:26:07 +0200 Subject: [PATCH 1/2] rename effectif columns --- app/helpers/application_helper.rb | 4 ++-- app/lib/api_entreprise/effectifs_adapter.rb | 6 +++--- db/migrate/20200421174642_rename_effectif_mensuel.rb | 7 +++++++ db/schema.rb | 8 ++++---- spec/controllers/users/dossiers_controller_spec.rb | 2 +- spec/lib/api_entreprise/effectifs_adapter_spec.rb | 2 +- spec/services/api_entreprise_service_spec.rb | 2 +- 7 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20200421174642_rename_effectif_mensuel.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 262f142a5..e7f399a48 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -131,8 +131,8 @@ module ApplicationHelper end def try_format_mois_effectif(etablissement) - if etablissement.effectif_mois.present? && etablissement.effectif_annee.present? - [etablissement.effectif_mois, etablissement.effectif_annee].join('/') + if etablissement.entreprise_effectif_mois.present? && etablissement.entreprise_effectif_annee.present? + [etablissement.entreprise_effectif_mois, etablissement.entreprise_effectif_annee].join('/') else '' end diff --git a/app/lib/api_entreprise/effectifs_adapter.rb b/app/lib/api_entreprise/effectifs_adapter.rb index 61af1fe78..ae768a3f9 100644 --- a/app/lib/api_entreprise/effectifs_adapter.rb +++ b/app/lib/api_entreprise/effectifs_adapter.rb @@ -15,9 +15,9 @@ class ApiEntreprise::EffectifsAdapter < ApiEntreprise::Adapter def process_params if data_source[:effectifs_mensuels].present? { - effectif_mensuel: data_source[:effectifs_mensuels], - effectif_mois: @mois, - effectif_annee: @annee + entreprise_effectif_mensuel: data_source[:effectifs_mensuels], + entreprise_effectif_mois: @mois, + entreprise_effectif_annee: @annee } else {} diff --git a/db/migrate/20200421174642_rename_effectif_mensuel.rb b/db/migrate/20200421174642_rename_effectif_mensuel.rb new file mode 100644 index 000000000..9a92ad1aa --- /dev/null +++ b/db/migrate/20200421174642_rename_effectif_mensuel.rb @@ -0,0 +1,7 @@ +class RenameEffectifMensuel < ActiveRecord::Migration[5.2] + def change + rename_column :etablissements, :effectif_mensuel, :entreprise_effectif_mensuel + rename_column :etablissements, :effectif_mois, :entreprise_effectif_mois + rename_column :etablissements, :effectif_annee, :entreprise_effectif_annee + end +end diff --git a/db/schema.rb b/db/schema.rb index 91ca9849b..e7a2911e7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_04_09_075320) do +ActiveRecord::Schema.define(version: 2020_04_21_174642) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -310,9 +310,9 @@ ActiveRecord::Schema.define(version: 2020_04_09_075320) do t.datetime "created_at" t.datetime "updated_at" t.boolean "diffusable_commercialement" - t.string "effectif_mois" - t.string "effectif_annee" - t.decimal "effectif_mensuel" + t.string "entreprise_effectif_mois" + t.string "entreprise_effectif_annee" + t.decimal "entreprise_effectif_mensuel" t.index ["dossier_id"], name: "index_etablissements_on_dossier_id" end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 98bc45d37..5779e099a 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -327,7 +327,7 @@ describe Users::DossiersController, type: :controller do expect(dossier.etablissement.entreprise).to be_present expect(dossier.etablissement.exercices).to be_present expect(dossier.etablissement.association?).to be(true) - expect(dossier.etablissement.effectif_mensuel).to be_present + expect(dossier.etablissement.entreprise_effectif_mensuel).to be_present end end end diff --git a/spec/lib/api_entreprise/effectifs_adapter_spec.rb b/spec/lib/api_entreprise/effectifs_adapter_spec.rb index a8e586d6c..205545247 100644 --- a/spec/lib/api_entreprise/effectifs_adapter_spec.rb +++ b/spec/lib/api_entreprise/effectifs_adapter_spec.rb @@ -20,7 +20,7 @@ describe ApiEntreprise::EffectifsAdapter do end it "renvoie les effectifs du mois demandé" do - expect(subject[:effectif_mensuel]).to eq(100.5) + expect(subject[:entreprise_effectif_mensuel]).to eq(100.5) end end end diff --git a/spec/services/api_entreprise_service_spec.rb b/spec/services/api_entreprise_service_spec.rb index af5aec64b..ff6fec019 100644 --- a/spec/services/api_entreprise_service_spec.rb +++ b/spec/services/api_entreprise_service_spec.rb @@ -46,7 +46,7 @@ describe ApiEntrepriseService do expect(result[:siret]).to eq(siret) expect(result[:association_rna]).to eq(rna) expect(result[:exercices_attributes]).to_not be_empty - expect(result[:effectif_mensuel]).to eq(effectif_mensuel) + expect(result[:entreprise_effectif_mensuel]).to eq(effectif_mensuel) end end From 149b98007fef9c3658d984fc3d855abc4f7e27cb Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 21 Apr 2020 15:52:08 +0200 Subject: [PATCH 2/2] add effectif mensuel to graphql api --- app/graphql/schema.graphql | 14 ++++++++++++++ app/graphql/types/personne_morale_type.rb | 19 +++++++++++++++++++ app/models/entreprise.rb | 3 +++ app/models/etablissement.rb | 3 +++ app/serializers/entreprise_serializer.rb | 3 +++ .../dossiers/_identite_entreprise.html.haml | 2 +- .../api/v1/dossiers_controller_spec.rb | 3 +++ 7 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 7a933303c..6b0b895f4 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -686,10 +686,24 @@ enum DossierState { sans_suite } +type Effectif { + """ + Année de l'effectif mensuel + """ + annee: String! + + """ + Mois de l'effectif mensuel + """ + mois: String! + nb: Float! +} + type Entreprise { capitalSocial: BigInt! codeEffectifEntreprise: String! dateCreation: ISO8601Date! + effectifs: [Effectif!]! formeJuridique: String! formeJuridiqueCode: String! inlineAdresse: String! diff --git a/app/graphql/types/personne_morale_type.rb b/app/graphql/types/personne_morale_type.rb index 357805f6c..5bc5f176b 100644 --- a/app/graphql/types/personne_morale_type.rb +++ b/app/graphql/types/personne_morale_type.rb @@ -1,6 +1,12 @@ module Types class PersonneMoraleType < Types::BaseObject class EntrepriseType < Types::BaseObject + class EffectifType < Types::BaseObject + field :mois, String, null: false, description: "Mois de l'effectif mensuel" + field :annee, String, null: false, description: "Année de l'effectif mensuel" + field :nb, Float, null: false + end + field :siren, String, null: false field :capital_social, GraphQL::Types::BigInt, null: false field :numero_tva_intracommunautaire, String, null: false @@ -10,10 +16,23 @@ module Types field :raison_sociale, String, null: false field :siret_siege_social, String, null: false field :code_effectif_entreprise, String, null: false + field :effectifs, [EffectifType], null: false field :date_creation, GraphQL::Types::ISO8601Date, null: false field :nom, String, null: false field :prenom, String, null: false field :inline_adresse, String, null: false + + def effectifs + if object.effectif_mensuel.present? + [ + { + mois: object.effectif_mois, + annee: object.effectif_annee, + nb: object.effectif_mensuel + } + ] + end + end end class AssociationType < Types::BaseObject diff --git a/app/models/entreprise.rb b/app/models/entreprise.rb index 19cecd7e1..5fb6cf719 100644 --- a/app/models/entreprise.rb +++ b/app/models/entreprise.rb @@ -12,6 +12,9 @@ class Entreprise < Hashie::Dash property :raison_sociale property :siret_siege_social property :code_effectif_entreprise + property :effectif_mois + property :effectif_annee + property :effectif_mensuel property :date_creation property :nom property :prenom diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index 98584e672..4d3236e80 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -102,6 +102,9 @@ class Etablissement < ApplicationRecord raison_sociale: entreprise_raison_sociale, siret_siege_social: entreprise_siret_siege_social, code_effectif_entreprise: entreprise_code_effectif_entreprise, + effectif_mensuel: entreprise_effectif_mensuel, + effectif_mois: entreprise_effectif_mois, + effectif_annee: entreprise_effectif_annee, date_creation: entreprise_date_creation, nom: entreprise_nom, prenom: entreprise_prenom, diff --git a/app/serializers/entreprise_serializer.rb b/app/serializers/entreprise_serializer.rb index 3a52d7917..70437d8c8 100644 --- a/app/serializers/entreprise_serializer.rb +++ b/app/serializers/entreprise_serializer.rb @@ -8,6 +8,9 @@ class EntrepriseSerializer < ActiveModel::Serializer :raison_sociale, :siret_siege_social, :code_effectif_entreprise, + :effectif_mois, + :effectif_annee, + :effectif_mensuel, :date_creation, :nom, :prenom diff --git a/app/views/shared/dossiers/_identite_entreprise.html.haml b/app/views/shared/dossiers/_identite_entreprise.html.haml index b71041c74..51a5dc51f 100644 --- a/app/views/shared/dossiers/_identite_entreprise.html.haml +++ b/app/views/shared/dossiers/_identite_entreprise.html.haml @@ -32,7 +32,7 @@ %th.libelle Effectif mensuel = try_format_mois_effectif(etablissement) - %td= etablissement.effectif_mensuel + %td= etablissement.entreprise_effectif_mensuel %tr %th.libelle Effectif de l'organisation : %td= effectif(etablissement) diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index cfbcc11c5..a329464ac 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -197,6 +197,9 @@ describe API::V1::DossiersController do :raison_sociale, :siret_siege_social, :code_effectif_entreprise, + :effectif_mois, + :effectif_annee, + :effectif_mensuel, :date_creation, :nom, :prenom