commit
64849891b6
9 changed files with 79 additions and 59 deletions
|
@ -6,10 +6,6 @@ class API::V1::DossiersController < APIController
|
|||
error code: 401, desc: "Non authorisé"
|
||||
error code: 404, desc: "Procédure inconnue"
|
||||
|
||||
description <<-EOS
|
||||
Plop
|
||||
EOS
|
||||
|
||||
meta champs: {
|
||||
}
|
||||
|
||||
|
@ -17,8 +13,8 @@ class API::V1::DossiersController < APIController
|
|||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page])
|
||||
|
||||
render json: {dossiers: dossiers.map{|dossier| DossiersSerializer.new(dossier)}, pagination: pagination(dossiers)}, status: 200
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
render json: { dossiers: dossiers.map{ |dossier| DossiersSerializer.new(dossier) }, pagination: pagination(dossiers) }, status: 200
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render json: {}, status: 404
|
||||
end
|
||||
|
||||
|
@ -29,10 +25,6 @@ class API::V1::DossiersController < APIController
|
|||
error code: 401, desc: "Non authorisé"
|
||||
error code: 404, desc: "Procédure ou dossier inconnu"
|
||||
|
||||
description <<-EOS
|
||||
Plop
|
||||
EOS
|
||||
|
||||
meta champs: {
|
||||
|
||||
}
|
||||
|
@ -42,10 +34,9 @@ class API::V1::DossiersController < APIController
|
|||
dossier = procedure.dossiers.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.json { render json: {dossier: DossierSerializer.new(dossier).as_json}, status: 200 }
|
||||
format.csv { render csv: dossier.as_csv, status: 200 }
|
||||
format.json { render json: { dossier: DossierSerializer.new(dossier).as_json }, status: 200 }
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render json: {}, status: 404
|
||||
end
|
||||
|
||||
|
|
|
@ -5,10 +5,6 @@ class API::V1::ProceduresController < APIController
|
|||
error code: 401, desc: "Non authorisé"
|
||||
error code: 404, desc: "Procédure inconnue"
|
||||
|
||||
description <<-EOS
|
||||
Plop
|
||||
EOS
|
||||
|
||||
meta champs: {
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -246,8 +247,8 @@ class Dossier < ActiveRecord::Base
|
|||
return headers
|
||||
end
|
||||
|
||||
def followers_gestionnaires_emails
|
||||
follows.includes(:gestionnaire).map { |f| f.gestionnaire }.pluck(:email).join(' ')
|
||||
def followers_gestionnaires
|
||||
follows.includes(:gestionnaire).map(&:gestionnaire)
|
||||
end
|
||||
|
||||
def reset!
|
||||
|
@ -292,5 +293,4 @@ class Dossier < ActiveRecord::Base
|
|||
def serialize_value_for_export(value)
|
||||
value.nil? || value.kind_of?(Time) ? value : value.to_s
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,7 +4,13 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
:updated_at,
|
||||
:archived,
|
||||
:mandataire_social,
|
||||
:state
|
||||
:state,
|
||||
:simplified_state,
|
||||
:initiated_at,
|
||||
:received_at,
|
||||
:processed_at,
|
||||
:accompagnateurs,
|
||||
:invites
|
||||
|
||||
has_one :entreprise
|
||||
has_one :etablissement
|
||||
|
@ -14,4 +20,16 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
has_many :champs_private
|
||||
has_many :pieces_justificatives
|
||||
has_many :types_de_piece_justificative
|
||||
|
||||
def simplified_state
|
||||
object.decorate.display_state
|
||||
end
|
||||
|
||||
def accompagnateurs
|
||||
object.followers_gestionnaires.pluck(:email)
|
||||
end
|
||||
|
||||
def invites
|
||||
object.invites_gestionnaires.pluck(:email)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ class DossierTableExportSerializer < ActiveModel::Serializer
|
|||
:received_at,
|
||||
:processed_at
|
||||
|
||||
attribute :followers_gestionnaires_emails, key: :emails_accompagnateurs
|
||||
attribute :emails_accompagnateurs
|
||||
|
||||
attributes :individual_gender,
|
||||
:individual_prenom,
|
||||
|
@ -31,4 +31,8 @@ class DossierTableExportSerializer < ActiveModel::Serializer
|
|||
def individual_gender
|
||||
object.individual.try(:gender)
|
||||
end
|
||||
|
||||
def emails_accompagnateurs
|
||||
object.followers_gestionnaires.pluck(:email).join(' ')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,6 +45,17 @@
|
|||
"updated_at": "2008-09-01T08:05:00.000Z",
|
||||
"archived": false,
|
||||
"mandataire_social": false,
|
||||
"state": "updated",
|
||||
"simplified_state": "En construction",
|
||||
"initiated_at": "2017-04-11T12:00:12.000Z",
|
||||
"received_at": null,
|
||||
"processed_at": null,
|
||||
"accompagnateurs": [
|
||||
"gestionnaire@apientreprise.fr"
|
||||
],
|
||||
"invites": [
|
||||
"nom@domaine.fr"
|
||||
],
|
||||
"entreprise": {
|
||||
"siren": "440117620",
|
||||
"capital_social": 537100000,
|
||||
|
@ -174,4 +185,4 @@
|
|||
"recorded": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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] }
|
||||
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
|
||||
|
|
|
@ -572,7 +572,7 @@ describe Dossier do
|
|||
it { expect(subject[6]).to eq(date1) }
|
||||
it { expect(subject[7]).to eq(date2) }
|
||||
it { expect(subject[8]).to eq(date3) }
|
||||
it { expect(subject[9]).to eq(dossier.followers_gestionnaires_emails) }
|
||||
it { expect(subject[9]).to be_a_kind_of(String) }
|
||||
it { expect(subject[10]).to be_nil }
|
||||
it { expect(subject[11]).to be_nil }
|
||||
it { expect(subject[12]).to be_nil }
|
||||
|
@ -809,40 +809,6 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#followers_gestionnaires_emails' do
|
||||
|
||||
context 'when there is no follower' do
|
||||
let(:dossier) { create(:dossier, follows: []) }
|
||||
|
||||
subject { dossier.followers_gestionnaires_emails }
|
||||
|
||||
it { is_expected.to eq "" }
|
||||
end
|
||||
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
let(:follow) { create(:follow, gestionnaire: gestionnaire) }
|
||||
|
||||
context 'when there is 1 follower' do
|
||||
let(:dossier) { create(:dossier, follows: [follow]) }
|
||||
|
||||
subject { dossier.followers_gestionnaires_emails }
|
||||
|
||||
it { is_expected.to eq gestionnaire.email }
|
||||
end
|
||||
|
||||
let(:gestionnaire2) { create :gestionnaire}
|
||||
let(:follow2) { create(:follow, gestionnaire: gestionnaire2) }
|
||||
|
||||
context 'when there is 2 followers' do
|
||||
let(:dossier) { create(:dossier, follows: [follow, follow2]) }
|
||||
|
||||
subject { dossier.followers_gestionnaires_emails }
|
||||
|
||||
it { is_expected.to eq "#{gestionnaire.email} #{gestionnaire2.email}" }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#update_state_dates' do
|
||||
let(:state) { 'draft' }
|
||||
let(:dossier) { create(:dossier, state: state) }
|
||||
|
|
34
spec/serializers/dossier_table_export_serializer_spec.rb
Normal file
34
spec/serializers/dossier_table_export_serializer_spec.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe DossierTableExportSerializer do
|
||||
|
||||
describe '#emails_accompagnateurs' do
|
||||
|
||||
let(:gestionnaire){ create(:gestionnaire) }
|
||||
let(:follow) { create(:follow, gestionnaire: gestionnaire) }
|
||||
|
||||
subject { DossierTableExportSerializer.new(dossier).emails_accompagnateurs }
|
||||
|
||||
context 'when there is no accompagnateurs' do
|
||||
let(:dossier) { create(:dossier, follows: []) }
|
||||
|
||||
it { is_expected.to eq('') }
|
||||
end
|
||||
|
||||
context 'when there one accompagnateur' do
|
||||
let(:dossier) { create(:dossier, follows: [follow]) }
|
||||
|
||||
it { is_expected.to eq(gestionnaire.email) }
|
||||
end
|
||||
|
||||
context 'when there is 2 followers' do
|
||||
let(:gestionnaire2) { create :gestionnaire}
|
||||
let(:follow2) { create(:follow, gestionnaire: gestionnaire2) }
|
||||
let(:dossier) { create(:dossier, follows: [follow, follow2]) }
|
||||
|
||||
it { is_expected.to eq "#{gestionnaire.email} #{gestionnaire2.email}" }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue