Test and fix all possible cases of champ carte serialization

This commit is contained in:
Paul Chavard 2018-11-29 23:10:13 +01:00
parent c2161fbf85
commit 097a15d624
3 changed files with 108 additions and 42 deletions

View file

@ -51,7 +51,7 @@ class Champs::CarteChamp < Champ
# We used to store in the value column a json array with coordinates.
if geo_json.is_a?(Array)
# If it is a coordinates array, format it as a GEO-JSON
GeojsonService.to_json_polygon_for_selection_utilisateur(geo_json)
JSON.parse(GeojsonService.to_json_polygon_for_selection_utilisateur(geo_json))
else
# It is already a GEO-JSON
geo_json

View file

@ -12,11 +12,9 @@ class ChampSerializer < ActiveModel::Serializer
def value
case object
when GeoArea
object.geometry
object.geometry.to_json
when Champs::CarteChamp
if object.value.present?
JSON.parse(object.value)
end
object.user_geometry.to_json
when Champs::DecimalNumberChamp
if object.value.present?
object.value.to_f
@ -71,7 +69,7 @@ class ChampSerializer < ActiveModel::Serializer
libelle: legacy_carto_libelle,
type_champ: legacy_carto_type_champ,
order_place: -1,
descripton: ''
description: ''
}
end