2015-12-21 17:51:49 +01:00
|
|
|
class ProcedureSerializer < ActiveModel::Serializer
|
2018-10-22 19:22:51 +02:00
|
|
|
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,
|
2017-07-10 23:42:33 +02:00
|
|
|
:archived_at,
|
2017-06-12 13:49:51 +02:00
|
|
|
:geographic_information,
|
2018-10-22 19:22:51 +02:00
|
|
|
:total_dossier,
|
2018-10-22 19:23:30 +02:00
|
|
|
:link,
|
2022-10-06 11:03:49 +02:00
|
|
|
:state,
|
|
|
|
:direction
|
2016-01-12 15:11:42 +01:00
|
|
|
|
2020-08-05 18:40:47 +02: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
|
2019-01-10 15:55:04 +01:00
|
|
|
has_many :types_de_piece_justificative
|
2019-09-09 16:18:42 +02:00
|
|
|
belongs_to :service, serializer: ServiceSerializer
|
2018-10-22 19:22:51 +02:00
|
|
|
|
2022-10-06 11:03:49 +02:00
|
|
|
def direction
|
|
|
|
""
|
|
|
|
end
|
|
|
|
|
2018-10-31 10:29:03 +01:00
|
|
|
def archived_at
|
2019-11-14 09:43:45 +01:00
|
|
|
object.closed_at&.in_time_zone('UTC')
|
2018-10-31 10:29:03 +01:00
|
|
|
end
|
|
|
|
|
2018-10-22 19:22:51 +02:00
|
|
|
def link
|
2019-09-16 16:59:10 +02:00
|
|
|
if object.brouillon?
|
|
|
|
commencer_test_url(path: object.path)
|
|
|
|
else
|
|
|
|
commencer_url(path: object.path)
|
2018-10-22 19:22:51 +02:00
|
|
|
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
|
2018-10-22 19:24:38 +02:00
|
|
|
|
|
|
|
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
|
2018-10-22 19:24:38 +02:00
|
|
|
end
|
2019-01-10 15:55:04 +01:00
|
|
|
|
2019-01-10 15:56:18 +01:00
|
|
|
def types_de_champ
|
2022-11-16 12:46:33 +01:00
|
|
|
object.active_revision.types_de_champ_public.reject { |c| c.old_pj.present? }
|
|
|
|
end
|
|
|
|
|
|
|
|
def types_de_champ_private
|
|
|
|
object.active_revision.types_de_champ_private
|
2019-01-10 15:56:18 +01:00
|
|
|
end
|
|
|
|
|
2019-01-10 15:55:04 +01:00
|
|
|
def types_de_piece_justificative
|
2020-08-27 19:55:10 +02:00
|
|
|
PiecesJustificativesService.serialize_types_de_champ_as_type_pj(object.active_revision)
|
2019-01-10 15:55:04 +01:00
|
|
|
end
|
2015-12-21 17:51:49 +01:00
|
|
|
end
|