From 27d52dfce9d1dde5e94e770622260efdf1aed9df Mon Sep 17 00:00:00 2001 From: Angel Penchev Date: Wed, 3 Feb 2021 00:41:36 +0200 Subject: [PATCH] [Fix] exportToNormalEntity undefined entries Resolved an issue where non-getter methods were being stored as {undefined: undefined}. References #59, #60, #61 and #62. --- server/services/core/entities/utilities.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/server/services/core/entities/utilities.ts b/server/services/core/entities/utilities.ts index 8ee91ae..0c3d1b2 100644 --- a/server/services/core/entities/utilities.ts +++ b/server/services/core/entities/utilities.ts @@ -13,16 +13,19 @@ export function exportToNormalEntity( // @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](), - ] : []), + ]), ); }