demarches-normaliennes/app/serializers/dossier_table_export_serializer.rb

69 lines
1.2 KiB
Ruby
Raw Normal View History

class DossierTableExportSerializer < ActiveModel::Serializer
attributes :id,
2017-06-12 13:49:51 +02:00
:created_at,
:updated_at,
:archived,
2017-08-01 14:18:20 +02:00
:email,
2017-06-12 13:49:51 +02:00
:state,
:initiated_at,
:received_at,
:processed_at,
:motivation
2018-08-29 22:11:38 +02:00
attribute :emails_instructeurs
attributes :individual_gender,
2017-06-12 13:49:51 +02:00
:individual_prenom,
:individual_nom,
:individual_birthdate
2017-08-01 14:18:20 +02:00
def email
2018-05-30 18:45:46 +02:00
object.user&.email
2017-08-01 14:18:20 +02:00
end
def state
case object.state
when Dossier.states.fetch(:en_construction)
'initiated'
when Dossier.states.fetch(:en_instruction)
'received'
when Dossier.states.fetch(:accepte)
2017-12-04 18:00:12 +01:00
'closed'
when Dossier.states.fetch(:refuse)
2017-12-04 18:15:40 +01:00
'refused'
when Dossier.states.fetch(:sans_suite)
'without_continuation'
else
object.state
end
end
def initiated_at
object.en_construction_at
end
def received_at
object.en_instruction_at
end
def individual_prenom
2018-05-30 18:45:46 +02:00
object.individual&.prenom
end
def individual_nom
2018-05-30 18:45:46 +02:00
object.individual&.nom
end
def individual_birthdate
2018-05-30 18:45:46 +02:00
object.individual&.birthdate
end
def individual_gender
2018-05-30 18:45:46 +02:00
object.individual&.gender
end
2017-04-14 18:10:39 +02:00
2018-08-29 22:11:38 +02:00
def emails_instructeurs
2017-04-14 18:10:39 +02:00
object.followers_gestionnaires.pluck(:email).join(' ')
end
end