Skip to content

Commit

Permalink
bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Feb 21, 2020
1 parent b76038e commit 7c0b8d1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions x-pack/legacy/plugins/siem/public/containers/case/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,27 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { camelCase, isObject, set } from 'lodash';
import { camelCase, isArray, isObject, set } from 'lodash';
import { AllCases, AllCasesSnake, Case, CaseSnake } from './types';

export const getTypedPayload = <T>(a: unknown): T => a as T;

export const convertArrayToCamelCase = (arrayOfSnakes: unknown[]): unknown[] =>
arrayOfSnakes.reduce((acc: unknown[], value) => {
if (isArray(value)) {
return [...acc, convertArrayToCamelCase(value)];
} else if (isObject(value)) {
return [...acc, convertToCamelCase(value)];
} else {
return [...acc, value];
}
}, []);

export const convertToCamelCase = <T, U extends {}>(snakeCase: T): U =>
Object.entries(snakeCase).reduce((acc, [key, value]) => {
if (isObject(value)) {
if (isArray(value)) {
set(acc, camelCase(key), convertArrayToCamelCase(value));
} else if (isObject(value)) {
set(acc, camelCase(key), convertToCamelCase(value));
} else {
set(acc, camelCase(key), value);
Expand Down

0 comments on commit 7c0b8d1

Please sign in to comment.