Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed error exporting category with location formatted as object #3678

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions server/modules/category/manager/categoryExportManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading