From e480cc798f96aa59cec2bbbcd1e31c0544a6d618 Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Thu, 5 Dec 2024 21:58:14 +0100 Subject: [PATCH] fixed error exporting category with location formatted as object --- .../category/manager/categoryExportManager.js | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/server/modules/category/manager/categoryExportManager.js b/server/modules/category/manager/categoryExportManager.js index 46b06b9a93..93c5a732e5 100644 --- a/server/modules/category/manager/categoryExportManager.js +++ b/server/modules/category/manager/categoryExportManager.js @@ -11,22 +11,37 @@ import * as CategoryRepository from '../repository/categoryRepository' const levelPositionField = 'level' +const parsePoint = (geometryPoint) => { + if (Objects.isEmpty(geometryPoint)) return null + const point = Points.parse(geometryPoint) + if (point) return point + try { + return JSON.parse(geometryPoint) + } catch (error) { + return null + } +} + +const transformGeometryPointExtraProperty = ({ extraDef, obj }) => { + // split geometry point into separate columns + const extraDefName = ExtraPropDef.getName(extraDef) + const geometryPoint = obj[extraDefName] + const point = parsePoint(geometryPoint) + delete obj[extraDefName] + if (point) { + obj[extraDefName + '_x'] = point.x + obj[extraDefName + '_y'] = point.y + obj[extraDefName + '_srs'] = point.srs + } +} + const categoryItemExportTransformer = ({ category, language = null, includeLevelPosition = false }) => (obj) => { const extraDefs = Category.getItemExtraDefsArray(category) extraDefs.forEach((extraDef) => { if (ExtraPropDef.getDataType(extraDef) === ExtraPropDef.dataTypes.geometryPoint) { - // split geometry point into separate columns - const extraDefName = ExtraPropDef.getName(extraDef) - const geometryPoint = obj[extraDefName] - if (!Objects.isEmpty(geometryPoint)) { - const point = Points.parse(geometryPoint) - delete obj[extraDefName] - obj[extraDefName + '_x'] = point.x - obj[extraDefName + '_y'] = point.y - obj[extraDefName + '_srs'] = point.srs - } + transformGeometryPointExtraProperty({ extraDef, obj }) } }) if (language) {