Skip to content

Commit

Permalink
fixup! refactor: enrich types from server config api (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi committed May 18, 2020
1 parent 5181417 commit ea45359
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/app/core/models/server-config/server-config.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { omit } from 'lodash-es';
import { mapValues, omit } from 'lodash-es';

import { ServerConfigData, ServerConfigDataEntry } from './server-config.interface';
import { ServerConfig } from './server-config.model';
Expand All @@ -16,11 +16,6 @@ export class ServerConfigMapper {
}
return val;
}
private static transformTypes(obj) {
return Object.entries(obj)
.map(v => v)
.reduce((acc, val) => ({ ...acc, [val[0]]: ServerConfigMapper.transformType(val[1]) }), {});
}

private static mapEntries(entries: ServerConfigDataEntry[]) {
return entries.reduce(
Expand All @@ -29,10 +24,11 @@ export class ServerConfigMapper {
[entry.id]: Array.isArray(entry.elements)
? // do recursion if elements array is set
ServerConfigMapper.mapEntries(entry.elements)
: // transform string types to better values
ServerConfigMapper.transformTypes(
: mapValues(
// filter out unnecessary 'id' attribute
omit(entry, 'id')
omit(entry, 'id'),
// transform string types to better values
ServerConfigMapper.transformType
),
}),
{}
Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*"
},
{
Expand Down

0 comments on commit ea45359

Please sign in to comment.