fix(BOOK-453): avoid linkConnection invalid * fix(BOOK-453): avoid linkConnection invalid * test * test * test * Merge master
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import type { z } from "zod"
|
|
|
|
import type { System } from "../schemas/system"
|
|
import type { startPageRefsSchema } from "./output"
|
|
|
|
export namespace StartPageEnum {
|
|
export namespace ContentStack {
|
|
export const enum blocks {
|
|
CardsGrid = "StartPageBlocksCardsGrid",
|
|
CarouselCards = "StartPageBlocksCarouselCards",
|
|
FullWidthCampaign = "StartPageBlocksFullWidthCampaign",
|
|
JoinScandicFriends = "StartPageBlocksJoinScandicFriends",
|
|
}
|
|
}
|
|
}
|
|
|
|
export interface StartPageRefs extends z.output<typeof startPageRefsSchema> {}
|
|
|
|
export function getConnections({ start_page }: StartPageRefs) {
|
|
const connections: System["system"][] = [start_page.system]
|
|
|
|
if (start_page.blocks) {
|
|
start_page.blocks.forEach((block) => {
|
|
switch (block.__typename) {
|
|
case StartPageEnum.ContentStack.blocks.FullWidthCampaign: {
|
|
block.full_width_campaign.full_width_campaignConnection.edges.forEach(
|
|
({ node }) => {
|
|
if (node.system) {
|
|
connections.push(node.system)
|
|
}
|
|
}
|
|
)
|
|
break
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
return connections
|
|
}
|