Skip to content

Commit

Permalink
[Fix] exportToNormalEntity undefined entries
Browse files Browse the repository at this point in the history
Resolved an issue where non-getter methods were being stored as
{undefined: undefined}.

References #59, #60, #61 and #62.
  • Loading branch information
angel-penchev committed Feb 2, 2021
1 parent be1ad0f commit 27d52df
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions server/services/core/entities/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ export function exportToNormalEntity<T extends Object, U extends Object>(
// @ts-ignore ts(2322) - This is so we still get return typing without TS
// complaining about potential type mismatch.
return Object.fromEntries(
Object.entries(object).map((entry) => entry[0].startsWith('get') ? [
// Converting object key from 'getKeyName' to 'keyName'
entry[0].replace(/get[A-Z]/, entry[0][3].toLowerCase()),
Object.entries(object)
.filter((entry) => entry[0].startsWith('get'))
.filter((entry) => typeof entry[1] === 'function')
.map((entry) => [
// Converting object key from 'getKeyName' to 'keyName'
entry[0].replace(/get[A-Z]/, entry[0][3].toLowerCase()),

// Checking whether there is a nested object within the value. If there
// is, this function is run on it. Otherwise only the result from the
// getter is stored.
typeof entry[1]() === 'object' ? exportToNormalEntity(entry[1]()) :
// Checking whether there is a nested object within the value. If
// there is, this function is run on it. Otherwise only the
// result from the getter is stored.
typeof entry[1]() === 'object' ? exportToNormalEntity(entry[1]()) :
entry[1](),
] : []),
]),
);
}

Expand Down

0 comments on commit 27d52df

Please sign in to comment.