Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSCwj84547: remove null items from payload #69

Merged
merged 1 commit into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading