refactor(SW-438): change name to teasercard
This commit is contained in:
54
server/routers/contentstack/schemas/sidebar/teaserCard.ts
Normal file
54
server/routers/contentstack/schemas/sidebar/teaserCard.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import {
|
||||
teaserCardBlockRefsSchema,
|
||||
teaserCardBlockSchema,
|
||||
transformCardBlockRefs,
|
||||
transformTeaserCardBlock,
|
||||
} from "../blocks/cardsGrid"
|
||||
|
||||
import { SidebarEnums } from "@/types/enums/sidebar"
|
||||
|
||||
export const teaserCardsSchema = z.object({
|
||||
typename: z
|
||||
.literal(SidebarEnums.blocks.TeaserCard)
|
||||
.optional()
|
||||
.default(SidebarEnums.blocks.TeaserCard),
|
||||
teaser_card: z
|
||||
.object({
|
||||
theme: z.enum(["featured", "default"]).nullable().default("default"),
|
||||
teaser_cardConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: teaserCardBlockSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
return {
|
||||
...transformTeaserCardBlock(data.teaser_cardConnection.edges[0].node),
|
||||
theme: data.theme,
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const teaserCardRefschema = z.object({
|
||||
teaser_card: z
|
||||
.object({
|
||||
teaser_cardConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: teaserCardBlockRefsSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
let card = null
|
||||
if (data.teaser_cardConnection.edges.length) {
|
||||
card = transformCardBlockRefs(data.teaser_cardConnection.edges[0].node)
|
||||
}
|
||||
return card
|
||||
}),
|
||||
})
|
||||
Reference in New Issue
Block a user