demarches-normaliennes/app/serializers/dossier_serializer.rb

97 lines
1.6 KiB
Ruby
Raw Normal View History

2016-01-20 15:48:46 +01:00
class DossierSerializer < ActiveModel::Serializer
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,
2017-06-12 13:49:51 +02:00
:accompagnateurs,
:invites
has_one :individual
has_one :entreprise
has_one :etablissement
has_many :cerfa
2016-03-14 10:34:46 +01:00
has_many :commentaires
has_many :champs_private
has_many :pieces_justificatives
2016-03-17 14:50:10 +01:00
has_many :types_de_piece_justificative
has_many :champs do
champs = object.champs + object.quartier_prioritaires + object.cadastres
if object.user_geometry.present?
champs << object.user_geometry
end
champs
end
2018-04-24 16:02:36 +02:00
def cerfa
[]
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
def entreprise
object.etablissement&.entreprise
end
def state
case object.state
when 'en_construction'
'initiated'
when 'en_instruction'
'received'
2017-12-04 18:00:12 +01:00
when 'accepte'
'closed'
2017-12-04 18:15:40 +01:00
when 'refuse'
'refused'
when 'sans_suite'
'without_continuation'
else
object.state
end
end
def simplified_state
object.decorate.display_state
end
2017-04-14 18:10:39 +02:00
def initiated_at
object.en_construction_at
end
def received_at
object.en_instruction_at
end
2017-04-14 18:10:39 +02:00
def accompagnateurs
object.followers_gestionnaires.pluck(:email)
end
2017-04-14 18:20:14 +02:00
def invites
object.invites_gestionnaires.pluck(:email)
end
private
def user_geometry(dossier)
{
value: dossier.geometry,
type_de_champ: {
id: -1,
libelle: 'user_geometry',
type_champ: 'user_geometry',
order_place: -1,
descripton: ''
}
}
end
end