Skip to content

Commit cd2b0b2

Browse files
feat: add nodes for locations external episerver api
1 parent 06646dd commit cd2b0b2

File tree

1 file changed

+17
-38
lines changed

1 file changed

+17
-38
lines changed

src/gatsby-node.js

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,20 @@ exports.sourceNodes = async ({ actions: { createNode }, cache, createNodeId, cre
319319
} = tempItem;
320320

321321
if (status === "fulfilled" && !isEmpty(nodeName) && !isEmpty(endpoint) && !isEmpty(data)) {
322-
if (nodeName === "OptimizelyStoreContent") {
323-
tempItem.value.data = data?.filter(({ LocationType }) => LocationType === "Store");
324-
} else if (nodeName === "OptimizelyHotelContent") {
325-
tempItem.value.data = data?.filter(({ LocationType }) => LocationType === "Hotel");
322+
if (nodeName === "OptimizelyStoresContent") {
323+
tempItem.value.data = data?.Locations?.filter((location) => location.LocationType === "Store")?.map((location) => {
324+
return {
325+
...location,
326+
LocationType: "Store"
327+
};
328+
});
329+
} else if (nodeName === "OptimizelyHotelsContent") {
330+
tempItem.value.data = data?.Locations?.filter((location) => location.LocationType === "Hotel")?.map((location) => {
331+
return {
332+
...location,
333+
LocationType: "Hotel"
334+
};
335+
});
326336
}
327337
}
328338

@@ -475,25 +485,8 @@ exports.onCreateNode = async ({ node, actions: { createNode, createNodeField },
475485
})
476486
)
477487
)
478-
.then((res) => {
479-
if (res && Array.isArray(res) && res?.length > 0) {
480-
const fields = [];
481-
482-
res?.map((field) => fields.push(field.id));
483-
484-
createNodeField({
485-
node,
486-
name: `localFile`,
487-
value: fields
488-
});
489-
}
490-
491-
return res;
492-
})
493-
.catch((err) => {
494-
console.error(err);
495-
return err;
496-
});
488+
.then((res) => res)
489+
.catch((err) => err);
497490
});
498491

499492
return expanded?.[expandedKey];
@@ -540,21 +533,7 @@ exports.onCreateNode = async ({ node, actions: { createNode, createNodeField },
540533
})
541534
)
542535
)
543-
.then((res) => {
544-
if (res && Array.isArray(res) && res?.length > 0) {
545-
const fields = [];
546-
547-
res?.map((field) => fields.push(field.id));
548-
549-
createNodeField({
550-
node,
551-
name: `localFile`,
552-
value: fields
553-
});
554-
}
555-
556-
return res;
557-
})
536+
.then((res) => res)
558537
.catch((err) => err);
559538

560539
return node;

0 commit comments

Comments
 (0)