Skip to content

Commit

Permalink
- Improved PlattarUtil.match() to be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidArayan committed Nov 25, 2024
1 parent 9cb76f5 commit fc64fb5
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions plattar-api/util/plattar-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,22 @@ PlattarUtil.reconstruct = (parent, json, options) => {
if (Array.isArray(data)) {
data.forEach((item) => {
const construct = PlattarUtil.create(key, item.id, server);
construct._attributes = item.attributes || {};

parent.relationships._put(construct);
if (construct) {
construct._attributes = item.attributes || {};

parent.relationships._put(construct);
}
});
}
else {
const construct = PlattarUtil.create(key, data.id, server);
construct._attributes = data.attributes || {};

parent.relationships._put(construct);
if (construct) {
construct._attributes = data.attributes || {};

parent.relationships._put(construct);
}
}
}
}
Expand Down Expand Up @@ -158,7 +164,11 @@ PlattarUtil.create = (type, id, server) => {
// dynamic class matching from a string type
const _DynamicClass = PlattarUtil.match(type);

return new _DynamicClass(id, server);
if (_DynamicClass) {
return new _DynamicClass(id, server);
}

return undefined;
};

/**
Expand Down Expand Up @@ -222,7 +232,10 @@ PlattarUtil.match = (type) => {
case Rating.type(): return Rating;
case Solution.type(): return Solution;
case Folder.type(): return Folder;
default: throw new Error("PlattarUtil.match(type) - provided type of \"" + type + "\" does not exist and cannot be created");
default: {
console.warn("PlattarUtil.match(type) - provided type of \"" + type + "\" does not exist and cannot be created");
return undefined;
}
}
};

Expand Down

0 comments on commit fc64fb5

Please sign in to comment.