Add human version translation for state

This commit is contained in:
Mathieu Magnin 2017-04-14 17:38:08 +02:00
parent d87989622c
commit 822c7cdd96
5 changed files with 12 additions and 6 deletions

View file

@ -13,7 +13,7 @@ class API::V1::DossiersController < APIController
procedure = current_administrateur.procedures.find(params[:procedure_id]) procedure = current_administrateur.procedures.find(params[:procedure_id])
dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page]) 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 render json: { dossiers: dossiers.map{ |dossier| DossiersSerializer.new(dossier) }, pagination: pagination(dossiers) }, status: 200
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render json: {}, status: 404 render json: {}, status: 404
end end
@ -34,7 +34,7 @@ class API::V1::DossiersController < APIController
dossier = procedure.dossiers.find(params[:id]) dossier = procedure.dossiers.find(params[:id])
respond_to do |format| respond_to do |format|
format.json { render json: {dossier: DossierSerializer.new(dossier).as_json}, status: 200 } format.json { render json: { dossier: DossierSerializer.new(dossier).as_json }, status: 200 }
end end
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render json: {}, status: 404 render json: {}, status: 404

View file

@ -292,5 +292,4 @@ class Dossier < ActiveRecord::Base
def serialize_value_for_export(value) def serialize_value_for_export(value)
value.nil? || value.kind_of?(Time) ? value : value.to_s value.nil? || value.kind_of?(Time) ? value : value.to_s
end end
end end

View file

@ -4,7 +4,8 @@ class DossierSerializer < ActiveModel::Serializer
:updated_at, :updated_at,
:archived, :archived,
:mandataire_social, :mandataire_social,
:state :state,
:simplified_state
has_one :entreprise has_one :entreprise
has_one :etablissement has_one :etablissement
@ -14,4 +15,8 @@ class DossierSerializer < ActiveModel::Serializer
has_many :champs_private has_many :champs_private
has_many :pieces_justificatives has_many :pieces_justificatives
has_many :types_de_piece_justificative has_many :types_de_piece_justificative
def simplified_state
object.decorate.display_state
end
end end

View file

@ -45,6 +45,8 @@
"updated_at": "2008-09-01T08:05:00.000Z", "updated_at": "2008-09-01T08:05:00.000Z",
"archived": false, "archived": false,
"mandataire_social": false, "mandataire_social": false,
"state": "updated",
"simplified_state": "En construction",
"entreprise": { "entreprise": {
"siren": "440117620", "siren": "440117620",
"capital_social": 537100000, "capital_social": 537100000,
@ -174,4 +176,4 @@
"recorded": true "recorded": true
} }
] ]
} }

View file

@ -115,7 +115,7 @@ describe API::V1::DossiersController do
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } } let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:body) { JSON.parse(retour.body, symbolize_names: true) } 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] }
subject { body[:dossier] } subject { body[:dossier] }
it 'return REST code 200', :show_in_doc do it 'return REST code 200', :show_in_doc do