2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-20 15:48:46 +01:00
|
|
|
class DossierSerializer < ActiveModel::Serializer
|
2018-11-06 18:45:29 +01:00
|
|
|
include DossierHelper
|
|
|
|
|
2016-01-20 15:48:46 +01:00
|
|
|
attributes :id,
|
2017-06-12 13:49:51 +02:00
|
|
|
:created_at,
|
|
|
|
:updated_at,
|
|
|
|
:archived,
|
2017-08-01 14:19:58 +02:00
|
|
|
:email,
|
2017-06-12 13:49:51 +02:00
|
|
|
:state,
|
|
|
|
:simplified_state,
|
|
|
|
:initiated_at,
|
|
|
|
:received_at,
|
|
|
|
:processed_at,
|
2017-06-15 17:36:30 +02:00
|
|
|
:motivation,
|
2018-10-10 09:06:32 +02:00
|
|
|
:instructeurs
|
2016-01-25 16:08:10 +01:00
|
|
|
|
2019-07-31 16:09:28 +02:00
|
|
|
attribute :attestation, if: :include_attestation?
|
|
|
|
attribute :justificatif_motivation, if: :include_justificatif_motivation?
|
|
|
|
|
2017-12-11 15:15:03 +01:00
|
|
|
has_one :individual
|
2016-01-25 16:08:10 +01:00
|
|
|
has_one :entreprise
|
|
|
|
has_one :etablissement
|
2016-03-16 15:34:35 +01:00
|
|
|
has_many :cerfa
|
2016-03-14 10:34:46 +01:00
|
|
|
has_many :commentaires
|
2016-08-08 12:52:30 +02:00
|
|
|
has_many :champs_private
|
2016-03-17 17:33:38 +01:00
|
|
|
has_many :pieces_justificatives
|
2016-03-17 14:50:10 +01:00
|
|
|
has_many :types_de_piece_justificative
|
2019-06-27 14:38:57 +02:00
|
|
|
has_many :avis
|
2017-04-14 17:38:08 +02:00
|
|
|
|
2018-11-06 14:14:22 +01:00
|
|
|
has_many :champs, serializer: ChampSerializer
|
2018-10-31 13:32:17 +01:00
|
|
|
|
|
|
|
def champs
|
2024-08-27 10:29:10 +02:00
|
|
|
champs = object.project_champs_public.reject { |c| c.type_de_champ.old_pj.present? }
|
2018-10-31 13:32:17 +01:00
|
|
|
|
2018-11-27 15:55:14 +01:00
|
|
|
if object.expose_legacy_carto_api?
|
2018-11-06 14:14:22 +01:00
|
|
|
champ_carte = champs.find do |champ|
|
|
|
|
champ.type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:carte)
|
|
|
|
end
|
|
|
|
|
|
|
|
if champ_carte.present?
|
2020-04-17 12:46:07 +02:00
|
|
|
champs_geo_areas = champ_carte.geo_areas.filter do |geo_area|
|
2020-04-09 17:32:20 +02:00
|
|
|
geo_area.source != GeoArea.sources.fetch(:selection_utilisateur)
|
2018-12-19 11:09:13 +01:00
|
|
|
end
|
2020-04-09 17:32:20 +02:00
|
|
|
champs_geo_areas << champ_carte.selection_utilisateur_legacy_geo_area
|
|
|
|
|
|
|
|
champs += champs_geo_areas.compact
|
2018-11-06 14:14:22 +01:00
|
|
|
end
|
2017-10-30 16:54:33 +01:00
|
|
|
end
|
2018-10-31 13:32:17 +01:00
|
|
|
|
2017-10-30 16:54:33 +01:00
|
|
|
champs
|
2017-10-27 15:36:07 +02:00
|
|
|
end
|
|
|
|
|
2024-08-27 10:29:10 +02:00
|
|
|
def champs_private
|
|
|
|
object.project_champs_private
|
|
|
|
end
|
|
|
|
|
2018-04-24 16:02:36 +02:00
|
|
|
def cerfa
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
2019-01-10 18:46:19 +01:00
|
|
|
def pieces_justificatives
|
2024-08-27 10:29:10 +02:00
|
|
|
object.project_champs_public.filter { |champ| champ.type_de_champ.old_pj }.map do |champ|
|
2024-02-07 17:31:54 +01:00
|
|
|
{
|
|
|
|
created_at: champ.created_at&.in_time_zone('UTC'),
|
|
|
|
type_de_piece_justificative_id: champ.type_de_champ.old_pj[:stable_id],
|
2024-10-21 11:51:34 +02:00
|
|
|
content_url: champ.type_de_champ.champ_value_for_api(champ, version: 1),
|
2024-02-07 17:31:54 +01:00
|
|
|
user: champ.dossier.user
|
|
|
|
}
|
|
|
|
end.flatten
|
2019-01-10 18:46:19 +01:00
|
|
|
end
|
|
|
|
|
2019-07-31 16:09:28 +02:00
|
|
|
def attestation
|
2019-08-01 14:07:35 +02:00
|
|
|
object.attestation&.pdf_url
|
2019-07-31 16:09:28 +02:00
|
|
|
end
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
def justificatif_motivation
|
2019-07-31 16:09:28 +02:00
|
|
|
Rails.application.routes.url_helpers.url_for(object.justificatif_motivation)
|
2019-02-18 17:52:15 +01:00
|
|
|
end
|
|
|
|
|
2019-01-10 18:49:21 +01:00
|
|
|
def types_de_piece_justificative
|
2020-08-27 19:55:10 +02:00
|
|
|
PiecesJustificativesService.serialize_types_de_champ_as_type_pj(object.revision)
|
2019-01-10 18:49:21 +01:00
|
|
|
end
|
|
|
|
|
2017-08-01 14:19:58 +02:00
|
|
|
def email
|
2018-05-30 18:45:46 +02:00
|
|
|
object.user&.email
|
2017-08-01 14:19:58 +02:00
|
|
|
end
|
|
|
|
|
2018-04-23 11:57:38 +02:00
|
|
|
def entreprise
|
|
|
|
object.etablissement&.entreprise
|
|
|
|
end
|
|
|
|
|
2017-12-14 15:51:45 +01:00
|
|
|
def state
|
2018-11-06 18:46:17 +01:00
|
|
|
dossier_legacy_state(object)
|
2017-12-14 15:51:45 +01:00
|
|
|
end
|
|
|
|
|
2017-04-14 17:38:08 +02:00
|
|
|
def simplified_state
|
2018-11-06 18:45:29 +01:00
|
|
|
dossier_display_state(object)
|
2017-04-14 17:38:08 +02:00
|
|
|
end
|
2017-04-14 18:10:39 +02:00
|
|
|
|
2017-12-14 15:51:45 +01:00
|
|
|
def initiated_at
|
2021-12-06 15:49:17 +01:00
|
|
|
object.depose_at&.in_time_zone('UTC')
|
2017-12-14 15:51:45 +01:00
|
|
|
end
|
|
|
|
|
2017-12-14 15:53:02 +01:00
|
|
|
def received_at
|
2018-10-31 10:29:03 +01:00
|
|
|
object.en_instruction_at&.in_time_zone('UTC')
|
2017-12-14 15:53:02 +01:00
|
|
|
end
|
|
|
|
|
2018-08-29 22:11:38 +02:00
|
|
|
def instructeurs
|
2019-10-15 18:32:18 +02:00
|
|
|
object.followers_instructeurs.map(&:email)
|
2017-04-14 18:10:39 +02:00
|
|
|
end
|
2017-04-14 18:20:14 +02:00
|
|
|
|
2018-10-31 10:29:03 +01:00
|
|
|
def created_at
|
|
|
|
object.created_at&.in_time_zone('UTC')
|
|
|
|
end
|
|
|
|
|
|
|
|
def updated_at
|
|
|
|
object.updated_at&.in_time_zone('UTC')
|
|
|
|
end
|
|
|
|
|
|
|
|
def processed_at
|
|
|
|
object.processed_at&.in_time_zone('UTC')
|
|
|
|
end
|
2019-07-31 16:09:28 +02:00
|
|
|
|
|
|
|
def include_attestation?
|
|
|
|
object.accepte?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_justificatif_motivation?
|
|
|
|
object.justificatif_motivation.attached?
|
|
|
|
end
|
2016-11-09 15:36:18 +01:00
|
|
|
end
|