fix: improve accountPage tRPC query
This commit is contained in:
122
server/routers/contentstack/accountPage/output.ts
Normal file
122
server/routers/contentstack/accountPage/output.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import {
|
||||
ContentEntries,
|
||||
DynamicContentComponents,
|
||||
} from "@/types/requests/myPages/accountpage"
|
||||
|
||||
const accountPageShortcuts = z.object({
|
||||
__typename: z.literal(ContentEntries.AccountPageContentShortcuts),
|
||||
title: z.string().optional(),
|
||||
preamble: z.string().optional(),
|
||||
shortcuts: z.object({
|
||||
title: z.string().optional(),
|
||||
preamble: z.string().optional(),
|
||||
shortcuts: z.array(
|
||||
z.object({
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
locale: z.string(),
|
||||
}),
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
text: z.string().optional(),
|
||||
open_in_new_tab: z.boolean(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
|
||||
const accountPageDynamicContent = z.object({
|
||||
__typename: z.literal(ContentEntries.AccountPageContentDynamicContent),
|
||||
dynamic_content: z.object({
|
||||
title: z.string().optional(),
|
||||
preamble: z.string().optional(),
|
||||
component: z.nativeEnum(DynamicContentComponents),
|
||||
link: z
|
||||
.object({
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
locale: z.string(),
|
||||
}),
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
// To validate the JSON content
|
||||
// https://zod.dev/?id=json-type
|
||||
const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()])
|
||||
type Literal = z.infer<typeof literalSchema>
|
||||
type Json = Literal | { [key: string]: Json } | Json[]
|
||||
const jsonSchema: z.ZodType<Json> = z.lazy(() =>
|
||||
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])
|
||||
)
|
||||
|
||||
const accountPageTextContent = z.object({
|
||||
__typename: z.literal(ContentEntries.AccountPageContentTextContent),
|
||||
text_content: z.object({
|
||||
content: z.object({
|
||||
json: jsonSchema,
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
const accountPageContentItem = z.discriminatedUnion("__typename", [
|
||||
accountPageShortcuts,
|
||||
accountPageDynamicContent,
|
||||
accountPageTextContent,
|
||||
])
|
||||
|
||||
export const validateAccountPageSchema = z.object({
|
||||
all_account_page: z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
content: z.array(accountPageContentItem),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
|
||||
export const validateAccountPageOverviewSchema = z.object({
|
||||
all_account_page: z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
content: z.array(accountPageContentItem),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
export const validateAccountPageBenefitsSchema = z.object({
|
||||
all_account_page: z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
content: z.array(z.object({})),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
Reference in New Issue
Block a user