Skip to content

Commit

Permalink
refactor with filter(Boolean) to remove null responses
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Mar 28, 2024
1 parent de19008 commit e1588db
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions lib/json-api-client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,22 @@
if ('linked' in response) {
for (typeName in response.linked) {
linkedResources = response.linked[typeName];
linkedResources.forEach((resourceData) => {
if (resourceData) {
this.type(typeName).create(resourceData, headers, response.meta);
}
linkedResources.filter(Boolean).forEach((resourceData) => {
this.type(typeName).create(resourceData, headers, response.meta);
});
}
}
results = [];
if ('data' in response) {
response.data.forEach((resourceData) => {
if (resourceData) {
results.push(this.type(resourceData.type).create(resourceData, headers, response.meta));
}
response.data.filter(Boolean).forEach((resourceData) => {
results.push(this.type(resourceData.type).create(resourceData, headers, response.meta));
});
} else {
for (typeName in response) {
resources = response[typeName];
if (indexOf.call(RESERVED_TOP_LEVEL_KEYS, typeName) < 0) {
resources.forEach((resourceData) => {
if (resourceData) {
results.push(this.type(typeName).create(resourceData, headers, response.meta));
}
resources.filter(Boolean).forEach((resourceData) => {
results.push(this.type(typeName).create(resourceData, headers, response.meta));
});
}
}
Expand Down

0 comments on commit e1588db

Please sign in to comment.