From 9776739af277db55d4ab69dc0ae90d300e2fefa6 Mon Sep 17 00:00:00 2001 From: Vitaliy Nijankovskiy Date: Fri, 25 Apr 2025 17:36:54 +0300 Subject: [PATCH] Fixed crash when relationship object doesn't have data key --- index.js | 1 + index.test.js | 1 + 2 files changed, 2 insertions(+) diff --git a/index.js b/index.js index 2699228..d78098f 100644 --- a/index.js +++ b/index.js @@ -59,6 +59,7 @@ const deserializeResource = (resource, included, transformFunc) => { Object.keys(relationships).forEach(key => { const relationship = relationships[key].data; + if (!relationship) return; if (Array.isArray(relationship)) { deserialized[transformFunc ? transformFunc(key) : key] = relationship.map(rel => { const includedResource = findIncluded(included, rel.type, rel.id); diff --git a/index.test.js b/index.test.js index b4679de..b90672d 100644 --- a/index.test.js +++ b/index.test.js @@ -39,6 +39,7 @@ const resp = { director: { data: { id: 1, type: "person" }, }, + studio: {} }, links: { self: "/movies/1",