From 757af12d424bb98c887e29dd15ff80443754d5b2 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Fri, 14 Apr 2017 18:20:14 +0200 Subject: [PATCH] Add invites to API --- app/models/dossier.rb | 1 + app/serializers/dossier_serializer.rb | 7 ++++++- doc/apipie_examples.json | 3 +++ spec/controllers/api/v1/dossiers_controller_spec.rb | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index fd1ea248f..f98e4e4c9 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -22,6 +22,7 @@ class Dossier < ActiveRecord::Base has_many :commentaires, dependent: :destroy has_many :invites, dependent: :destroy has_many :invites_user, class_name: 'InviteUser', dependent: :destroy + has_many :invites_gestionnaires, class_name: 'InviteGestionnaire', dependent: :destroy has_many :follows has_many :notifications, dependent: :destroy diff --git a/app/serializers/dossier_serializer.rb b/app/serializers/dossier_serializer.rb index f02c44115..73b7dcc8c 100644 --- a/app/serializers/dossier_serializer.rb +++ b/app/serializers/dossier_serializer.rb @@ -9,7 +9,8 @@ class DossierSerializer < ActiveModel::Serializer :initiated_at, :received_at, :processed_at, - :accompagnateurs + :accompagnateurs, + :invites has_one :entreprise has_one :etablissement @@ -27,4 +28,8 @@ class DossierSerializer < ActiveModel::Serializer def accompagnateurs object.followers_gestionnaires.pluck(:email) end + + def invites + object.invites_gestionnaires.pluck(:email) + end end diff --git a/doc/apipie_examples.json b/doc/apipie_examples.json index f1c906a0e..7010bc322 100644 --- a/doc/apipie_examples.json +++ b/doc/apipie_examples.json @@ -53,6 +53,9 @@ "accompagnateurs": [ "gestionnaire@apientreprise.fr" ], + "invites": [ + "nom@domaine.fr" + ], "entreprise": { "siren": "440117620", "capital_social": 537100000, diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index 3f55ce128..be00999ee 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -115,7 +115,7 @@ describe API::V1::DossiersController do let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } } let(:dossier_id) { dossier.id } let(:body) { JSON.parse(retour.body, symbolize_names: true) } - let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :accompagnateurs] } + let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :accompagnateurs, :invites] } subject { body[:dossier] } it 'return REST code 200', :show_in_doc do