Skip to content

Commit

Permalink
fix #97 (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunyel authored Apr 29, 2022
1 parent 36f7945 commit d22d77e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/getResponseParser/sanitizeResource.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { sanitizeResource } from './sanitizeResource';

describe('sanitizeResource', () => {
it('It keeps null values', () => {
expect(
sanitizeResource([
{ name: 'vendor', value: 'Test Vendor' },
{ name: 'brand', value: null },
])
).toEqual({
'0': { name: 'vendor', value: 'Test Vendor' },
'1': { name: 'brand', value: null },
});
});
});
13 changes: 7 additions & 6 deletions src/getResponseParser/sanitizeResource.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
export const sanitizeResource = (data: any = {}) => {
const result: any = Object.keys(data).reduce((acc, key) => {
export const sanitizeResource = (data: any = {}): object => {
const result = Object.keys(data).reduce((acc, key) => {
if (key.startsWith('_')) {
return acc;
}

const dataKey = data[key];

if (dataKey === null || dataKey === undefined) {
return acc;
}
if (Array.isArray(dataKey)) {
if (dataKey[0] && typeof dataKey[0] === 'object') {
// if var is an array of reference objects with id properties
Expand All @@ -29,7 +26,11 @@ export const sanitizeResource = (data: any = {}) => {
}
}

if (typeof dataKey === 'object') {
if (
typeof dataKey === 'object' &&
dataKey !== null &&
dataKey !== undefined
) {
return {
...acc,
...(dataKey &&
Expand Down

0 comments on commit d22d77e

Please sign in to comment.