refactor(SW-194): update naming
This commit is contained in:
75
server/routers/contentstack/schemas/blocks/hotelFaq.ts
Normal file
75
server/routers/contentstack/schemas/blocks/hotelFaq.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import {
|
||||
accordionItemsSchema,
|
||||
globalFaqConnectionRefs,
|
||||
specificFaqConnectionRefs,
|
||||
} from "./accordion"
|
||||
|
||||
import { BlocksEnums } from "@/types/enums/blocks"
|
||||
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
||||
|
||||
export const hotelFaqSchema = z
|
||||
.object({
|
||||
typename: z
|
||||
.literal(BlocksEnums.block.Accordion)
|
||||
.optional()
|
||||
.default(BlocksEnums.block.Accordion),
|
||||
title: z.string().optional().default(""),
|
||||
global_faqConnection: z
|
||||
.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
questions: accordionItemsSchema,
|
||||
}),
|
||||
})
|
||||
),
|
||||
})
|
||||
.optional(),
|
||||
specific_faq: z
|
||||
.object({
|
||||
questions: accordionItemsSchema,
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.transform((data) => {
|
||||
const array = []
|
||||
array.push(
|
||||
data.global_faqConnection?.edges.flatMap(({ node: faqConnection }) => {
|
||||
return faqConnection.questions
|
||||
}) || []
|
||||
)
|
||||
array.push(data.specific_faq?.questions || [])
|
||||
return { ...data, faq: array.flat(2) }
|
||||
})
|
||||
|
||||
export const hotelFaqRefsSchema = z
|
||||
.object({
|
||||
__typename: z
|
||||
.literal(HotelPageEnum.ContentStack.blocks.Faq)
|
||||
.optional()
|
||||
.default(HotelPageEnum.ContentStack.blocks.Faq),
|
||||
global_faqConnection: globalFaqConnectionRefs.optional(),
|
||||
specific_faq: specificFaqConnectionRefs.optional(),
|
||||
})
|
||||
.transform((data) => {
|
||||
const array = []
|
||||
array.push(
|
||||
data.global_faqConnection?.edges.flatMap(({ node: faqConnection }) => {
|
||||
return faqConnection.questions.flatMap((question) =>
|
||||
question.answer.embedded_itemsConnection.edges.flatMap(
|
||||
({ node }) => node.system
|
||||
)
|
||||
)
|
||||
}) || []
|
||||
)
|
||||
array.push(
|
||||
data.specific_faq?.questions.flatMap((question) =>
|
||||
question.answer.embedded_itemsConnection.edges.flatMap(
|
||||
({ node }) => node.system
|
||||
)
|
||||
) || []
|
||||
)
|
||||
return array.flat(2)
|
||||
})
|
||||
Reference in New Issue
Block a user