diff --git a/plugins/catalog-backend/src/service/request/parseEntityTransformParams.ts b/plugins/catalog-backend/src/service/request/parseEntityTransformParams.ts index e09289d5c0..9bbe9e7861 100644 --- a/plugins/catalog-backend/src/service/request/parseEntityTransformParams.ts +++ b/plugins/catalog-backend/src/service/request/parseEntityTransformParams.ts @@ -20,22 +20,20 @@ import lodash from 'lodash'; import { RecursivePartial } from '../../util/RecursivePartial'; import { parseStringsParam } from './common'; -function getPathArray(input: Entity, field: string) { - const pathArray = []; - let currentPathPart = ''; +function getPathArrayAndValue(input: Entity, field: string) { + return field.split('.').reduce( + ([pathArray, inputSubset], pathPart, index, fieldParts) => { + if (Object.hasOwn(inputSubset, pathPart)) { + return [pathArray.concat(pathPart), inputSubset[pathPart]]; + } else if (fieldParts[index + 1] !== undefined) { + fieldParts[index + 1] = `${pathPart}.${fieldParts[index + 1]}`; + return [pathArray, inputSubset]; + } - for (const pathPart of field.split('.')) { - currentPathPart += pathPart; - - if (lodash.has(input, pathArray.concat(currentPathPart))) { - pathArray.push(currentPathPart); - currentPathPart = ''; - } else { - currentPathPart += '.'; - } - } - - return pathArray; + return [pathArray, undefined]; + }, + [[] as unknown as string, input as any], + ); } export function parseEntityTransformParams( @@ -64,9 +62,8 @@ export function parseEntityTransformParams( const output: RecursivePartial = {}; for (const field of fields) { - const pathArray = getPathArray(input, field); + const [pathArray, value] = getPathArrayAndValue(input, field); - const value = lodash.get(input, pathArray); if (value !== undefined) { lodash.set(output, pathArray, value); }