demarches-normaliennes/app/serializers/procedure_serializer.rb

54 lines
1.2 KiB
Ruby
Raw Normal View History

2015-12-21 17:51:49 +01:00
class ProcedureSerializer < ActiveModel::Serializer
include Rails.application.routes.url_helpers
2016-01-12 15:11:42 +01:00
attribute :libelle, key: :label
2015-12-21 17:51:49 +01:00
attributes :id,
2017-06-12 13:49:51 +02:00
:description,
:organisation,
:direction,
:archived_at,
2017-06-12 13:49:51 +02:00
:geographic_information,
:total_dossier,
2018-10-22 19:23:30 +02:00
:link,
:state
2016-01-12 15:11:42 +01:00
has_one :geographic_information, serializer: ModuleApiCartoSerializer
2016-08-02 16:13:15 +02:00
has_many :types_de_champ, serializer: TypeDeChampSerializer
has_many :types_de_champ_private, serializer: TypeDeChampSerializer
has_many :types_de_piece_justificative
belongs_to :service, serializer: ServiceSerializer
def archived_at
object.closed_at&.in_time_zone('UTC')
end
def link
if object.brouillon?
commencer_test_url(path: object.path)
else
commencer_url(path: object.path)
end
end
2018-10-22 19:23:30 +02:00
def state
2019-12-18 13:28:29 +01:00
object.aasm_state
2018-10-22 19:23:30 +02:00
end
def geographic_information
2018-11-27 15:55:14 +01:00
if object.expose_legacy_carto_api?
object.module_api_carto
else
ModuleAPICarto.new(procedure: object)
end
end
def types_de_champ
object.types_de_champ.reject { |c| c.old_pj.present? }
end
def types_de_piece_justificative
PiecesJustificativesService.serialize_types_de_champ_as_type_pj(object)
end
2015-12-21 17:51:49 +01:00
end