diff --git a/src/app/core/models/server-config/server-config.interface.ts b/src/app/core/models/server-config/server-config.interface.ts index 46d4aa5dfc..11c0d671d0 100644 --- a/src/app/core/models/server-config/server-config.interface.ts +++ b/src/app/core/models/server-config/server-config.interface.ts @@ -1,9 +1,7 @@ export interface ServerConfigDataEntry { - id: string; - elements?: ServerConfigDataEntry[]; - [key: string]: string | boolean | number | string[] | ServerConfigDataEntry[]; + [key: string]: string | boolean | number | string[] | ServerConfigDataEntry; } export interface ServerConfigData { - data: ServerConfigDataEntry[]; + data: ServerConfigDataEntry; } diff --git a/src/app/core/models/server-config/server-config.mapper.spec.ts b/src/app/core/models/server-config/server-config.mapper.spec.ts index 5e880632a2..5da110c55f 100644 --- a/src/app/core/models/server-config/server-config.mapper.spec.ts +++ b/src/app/core/models/server-config/server-config.mapper.spec.ts @@ -5,19 +5,17 @@ describe('Server Config Mapper', () => { describe('fromData', () => { it(`should return the ServerConfig when getting ServerConfigData`, () => { const config = ServerConfigMapper.fromData({ - data: [ - { applicationType: 'intershop.B2CResponsive', id: 'application', urlIdentifier: '-' }, - { acceleration: true, id: 'basket' }, - { id: 'general', locales: ['en_US', 'de_DE'] }, - { + data: { + application: { applicationType: 'intershop.B2CResponsive', id: 'application', urlIdentifier: '-' }, + basket: { acceleration: true, id: 'basket' }, + general: { id: 'general', locales: ['en_US', 'de_DE'] }, + services: { id: 'services', - elements: [ - { id: 'captcha', siteKey: 'ASDF' }, - { id: 'gtm', token: 'QWERTY', monitor: 'true' }, - { id: 'deeper', elements: [{ id: 'hidden', foo: 'bar', num: 123, alt: '123' }] }, - ], + captcha: { id: 'captcha', siteKey: 'ASDF' }, + gtm: { id: 'gtm', token: 'QWERTY', monitor: 'true' }, + deeper: { id: 'deeper', hidden: { id: 'hidden', foo: 'bar', num: 123, alt: '123' } }, }, - ], + }, }); expect(config).toMatchInlineSnapshot(` diff --git a/src/app/core/models/server-config/server-config.mapper.ts b/src/app/core/models/server-config/server-config.mapper.ts index e56426b729..dab9fbb4aa 100644 --- a/src/app/core/models/server-config/server-config.mapper.ts +++ b/src/app/core/models/server-config/server-config.mapper.ts @@ -1,4 +1,4 @@ -import { mapValues, omit } from 'lodash-es'; +import { omit } from 'lodash-es'; import { ServerConfigData, ServerConfigDataEntry } from './server-config.interface'; import { ServerConfig } from './server-config.model'; @@ -17,19 +17,19 @@ export class ServerConfigMapper { return val; } - private static mapEntries(entries: ServerConfigDataEntry[]) { - return entries.reduce( + private static mapEntries(entries: ServerConfigDataEntry): ServerConfig { + return Object.entries(entries).reduce( (acc, entry) => ({ ...acc, - [entry.id]: Array.isArray(entry.elements) - ? // do recursion if elements array is set - ServerConfigMapper.mapEntries(entry.elements) - : mapValues( - // filter out unnecessary 'id' attribute - omit(entry, 'id'), - // transform string types to better values - ServerConfigMapper.transformType - ), + [entry[0]]: + typeof entry[1] === 'object' && !Array.isArray(entry[1]) + ? // do recursion if we find an object + ServerConfigMapper.mapEntries( + // get rid of id + omit(entry[1], 'id') + ) + : // improve data quality + ServerConfigMapper.transformType(entry[1]), }), {} ); diff --git a/tslint.json b/tslint.json index 9e9525778f..de9d9ddd78 100644 --- a/tslint.json +++ b/tslint.json @@ -337,7 +337,7 @@ "from": "lodash.*" }, { - "import": "^(?!(range|uniq|memoize|once|groupBy|countBy|flatten|isEqual|intersection|omit|pick|mapValues)$).*", + "import": "^(?!(range|uniq|memoize|once|groupBy|countBy|flatten|isEqual|intersection|omit|pick)$).*", "from": "lodash.*" }, {