Skip to content

Commit

Permalink
CSCwj84547: remove null items from payload
Browse files Browse the repository at this point in the history
  • Loading branch information
iventura committed May 2, 2024
1 parent afc1857 commit 287734d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/tryout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ export const getCleanObject = obj => {
const decorate = obj => {
return {
...obj,
removeUndefinedFields: function removeUndefinedFields() {
removeUndefinedAndNullFields: function removeUndefinedAndNullFields() {
const entries = Object.entries(this);
if (entries.length === 0) return this;

entries.forEach(([key, value]) => {
if (this[key] === undefined) {
if (this[key] === undefined || value === null) {
delete this[key];
}

const isObjectNotArray = typeof this[key] === 'object' && !Array.isArray(value);
if (isObjectNotArray) {
removeUndefinedFields.bind(this[key])();
removeUndefinedAndNullFields.bind(this[key])();
}
});
return this;
Expand All @@ -153,7 +153,7 @@ export const getCleanObject = obj => {
};

const decoratedObject = decorate(obj);
return decoratedObject.removeUndefinedFields().cleanArrayFields().omitFunctionFields();
return decoratedObject.removeUndefinedAndNullFields().cleanArrayFields().omitFunctionFields();
};

export const mapStatusCodeToType = (code: number) => {
Expand Down

0 comments on commit 287734d

Please sign in to comment.