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 2f768bf977e..46d4aa5dfca 100644 --- a/src/app/core/models/server-config/server-config.interface.ts +++ b/src/app/core/models/server-config/server-config.interface.ts @@ -1,7 +1,7 @@ export interface ServerConfigDataEntry { id: string; elements?: ServerConfigDataEntry[]; - [key: string]: string | boolean | string[] | ServerConfigDataEntry[]; + [key: string]: string | boolean | number | string[] | ServerConfigDataEntry[]; } export interface ServerConfigData { 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 decd0acb8a4..5e880632a2c 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 @@ -13,8 +13,8 @@ describe('Server Config Mapper', () => { id: 'services', elements: [ { id: 'captcha', siteKey: 'ASDF' }, - { id: 'gtm', token: 'QWERTY', monitor: true }, - { id: 'deeper', elements: [{ id: 'hidden', foo: 'bar' }] }, + { id: 'gtm', token: 'QWERTY', monitor: 'true' }, + { id: 'deeper', elements: [{ id: 'hidden', foo: 'bar', num: 123, alt: '123' }] }, ], }, ], @@ -41,7 +41,9 @@ describe('Server Config Mapper', () => { }, "deeper": Object { "hidden": Object { + "alt": 123, "foo": "bar", + "num": 123, }, }, "gtm": Object { 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 237b0d2087b..e56426b7295 100644 --- a/src/app/core/models/server-config/server-config.mapper.ts +++ b/src/app/core/models/server-config/server-config.mapper.ts @@ -1,9 +1,22 @@ -import { omit } from 'lodash-es'; +import { mapValues, omit } from 'lodash-es'; import { ServerConfigData, ServerConfigDataEntry } from './server-config.interface'; import { ServerConfig } from './server-config.model'; export class ServerConfigMapper { + private static transformType(val) { + if (typeof val === 'string') { + if (!isNaN(+val)) { + return +val; + } else if (val === 'true') { + return true; + } else if (val === 'false') { + return false; + } + } + return val; + } + private static mapEntries(entries: ServerConfigDataEntry[]) { return entries.reduce( (acc, entry) => ({ @@ -11,8 +24,12 @@ export class ServerConfigMapper { [entry.id]: Array.isArray(entry.elements) ? // do recursion if elements array is set ServerConfigMapper.mapEntries(entry.elements) - : // filter out unnecessary 'id' attribute - omit(entry, 'id'), + : mapValues( + // filter out unnecessary 'id' attribute + omit(entry, 'id'), + // transform string types to better values + ServerConfigMapper.transformType + ), }), {} ); diff --git a/tslint.json b/tslint.json index a2539672ff0..af668d66ebf 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)$).*", + "import": "^(?!(range|uniq|memoize|once|groupBy|countBy|flatten|isEqual|intersection|omit|pick|mapValues)$).*", "from": "lodash.*" }, {