feat: improve structure and error handling

This commit is contained in:
Michael Zetterberg
2024-05-14 15:55:46 +02:00
parent 01587d7fd5
commit f5108d1a8e
104 changed files with 1505 additions and 1570 deletions
@@ -6,49 +6,47 @@ import type { NodeRefs } from "@/types/requests/utils/refs"
export function getConnections(refs: LoyaltyPageRefsDataRaw) {
const connections: Edges<NodeRefs>[] = []
refs.all_loyalty_page.items.forEach((ref) => {
if (ref.blocks) {
ref.blocks.forEach((item) => {
switch (item.__typename) {
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksContent: {
if (item.content.content.embedded_itemsConnection.edges.length) {
connections.push(item.content.content.embedded_itemsConnection)
}
break
}
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksCardGrid: {
item.card_grid.cards.forEach((card) => {
if (card.referenceConnection.edges.length) {
connections.push(card.referenceConnection)
}
})
break
}
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksShortcuts: {
item.shortcuts.shortcuts.forEach((shortcut) => {
if (shortcut.linkConnection.edges.length) {
connections.push(shortcut.linkConnection)
}
})
break
}
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksDynamicContent: {
if (item.dynamic_content.link.pageConnection.edges.length) {
connections.push(item.dynamic_content.link.pageConnection)
}
break
if (refs.loyalty_page.blocks) {
refs.loyalty_page.blocks.forEach((item) => {
switch (item.__typename) {
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksContent: {
if (item.content.content.embedded_itemsConnection.edges.length) {
connections.push(item.content.content.embedded_itemsConnection)
}
break
}
})
}
if (ref.sidebar) {
ref.sidebar?.forEach((item) => {
if (item.content.content.embedded_itemsConnection.edges.length) {
connections.push(item.content.content.embedded_itemsConnection)
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksCardGrid: {
item.card_grid.cards.forEach((card) => {
if (card.referenceConnection.edges.length) {
connections.push(card.referenceConnection)
}
})
break
}
})
}
})
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksShortcuts: {
item.shortcuts.shortcuts.forEach((shortcut) => {
if (shortcut.linkConnection.edges.length) {
connections.push(shortcut.linkConnection)
}
})
break
}
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksDynamicContent: {
if (item.dynamic_content.link.pageConnection.edges.length) {
connections.push(item.dynamic_content.link.pageConnection)
}
break
}
}
})
}
if (refs.loyalty_page.sidebar) {
refs.loyalty_page.sidebar?.forEach((item) => {
if (item.content.content.embedded_itemsConnection.edges.length) {
connections.push(item.content.content.embedded_itemsConnection)
}
})
}
return connections
}