-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created univertial utility method for converting entity exports to normal usable but not frozen data. References #59, #60, #61 and #62.
- Loading branch information
1 parent
426e390
commit 05b5326
Showing
4 changed files
with
65 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Converts an entity export object to normal object. | ||
* | ||
* @export | ||
* @template T - export object type | ||
* @template U - normalized object type | ||
* @param {T} object - export object | ||
* @return {U} - normalized object | ||
*/ | ||
export function exportToNormalEntity<T extends Object, U extends Object>( | ||
object: T, | ||
): U { | ||
// @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()), | ||
|
||
// 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](), | ||
] : []), | ||
); | ||
} | ||
|
||
const entityUtilities = Object.freeze({ | ||
exportToNormalEntity: exportToNormalEntity, | ||
}); | ||
|
||
export default entityUtilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
server/services/order-service/src/entities/order/order-decompress.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters