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

View File

@@ -168,16 +168,12 @@ const loyaltyPageSidebarItem = z.discriminatedUnion("__typename", [
])
export const validateLoyaltyPageSchema = z.object({
all_loyalty_page: z.object({
items: z.array(
z.object({
title: z.string(),
heading: z.string().nullable(),
blocks: z.array(loyaltyPageBlockItem).nullable(),
sidebar: z.array(loyaltyPageSidebarItem).nullable(),
system: z.object({ uid: z.string() }),
})
),
loyalty_page: z.object({
title: z.string(),
heading: z.string().nullable(),
blocks: z.array(loyaltyPageBlockItem).nullable(),
sidebar: z.array(loyaltyPageSidebarItem).nullable(),
system: z.object({ uid: z.string() }),
}),
})
@@ -257,7 +253,7 @@ export type Sidebar = JoinLoyaltyContact | RteSidebarContent
export type LoyaltyPageDataRaw = z.infer<typeof validateLoyaltyPageSchema>
type LoyaltyPageRaw = LoyaltyPageDataRaw["all_loyalty_page"]["items"][0]
type LoyaltyPageRaw = LoyaltyPageDataRaw["loyalty_page"]
export type LoyaltyPage = Omit<LoyaltyPageRaw, "blocks" | "sidebar"> & {
blocks: Block[]
@@ -342,17 +338,13 @@ const loyaltyPageSidebarRefsItem = z.discriminatedUnion("__typename", [
])
export const validateLoyaltyPageRefsSchema = z.object({
all_loyalty_page: z.object({
items: z.array(
z.object({
blocks: z.array(loyaltyPageBlocRefsItem).nullable(),
sidebar: z.array(loyaltyPageSidebarRefsItem).nullable(),
system: z.object({
content_type_uid: z.string(),
uid: z.string(),
}),
})
),
loyalty_page: z.object({
blocks: z.array(loyaltyPageBlocRefsItem).nullable(),
sidebar: z.array(loyaltyPageSidebarRefsItem).nullable(),
system: z.object({
content_type_uid: z.string(),
uid: z.string(),
}),
}),
})