fix(SW-190): added imageVaultAsset schema

This commit is contained in:
Erik Tiekstra
2024-08-15 14:19:52 +02:00
parent 4f2bd0c2d6
commit 771338cc80
15 changed files with 164 additions and 149 deletions
@@ -85,6 +85,18 @@ export const loyaltyPageQueryRouter = router({
throw notFound(response)
}
const validatedLoyaltyPage = validateLoyaltyPageSchema.safeParse(
response.data.loyalty_page
)
if (!validatedLoyaltyPage.success) {
console.error(
`Failed to validate Loyaltypage Data - (lang: ${lang}, uid: ${uid})`
)
console.error(validatedLoyaltyPage.error)
return null
}
const blocks = response.data.loyalty_page.blocks
? response.data.loyalty_page.blocks.map((block: any) => {
switch (block.__typename) {
@@ -178,26 +190,17 @@ export const loyaltyPageQueryRouter = router({
})
: null
const loyaltyPage = {
console.log({ HERO_IMAGE: response.data.loyalty_page.hero_image })
const loyaltyPage: LoyaltyPage = {
heading: response.data.loyalty_page.heading,
preamble: response.data.loyalty_page.preamble,
hero_image: makeImageVaultImage(response.data.loyalty_page.hero_image),
heroImage: makeImageVaultImage(response.data.loyalty_page.hero_image),
system: response.data.loyalty_page.system,
blocks,
sidebar,
}
const validatedLoyaltyPage =
validateLoyaltyPageSchema.safeParse(loyaltyPage)
if (!validatedLoyaltyPage.success) {
console.error(
`Failed to validate Loyaltypage Data - (lang: ${lang}, uid: ${uid})`
)
console.error(validatedLoyaltyPage.error)
return null
}
const loyaltyTrackingData: TrackingSDKPageData = {
pageId: response.data.loyalty_page.system.uid,
lang: response.data.loyalty_page.system.locale as Lang,
@@ -209,7 +212,7 @@ export const loyaltyPageQueryRouter = router({
// Assert LoyaltyPage type to get correct typings for RTE fields
return {
loyaltyPage: validatedLoyaltyPage.data as LoyaltyPage,
loyaltyPage,
tracking: loyaltyTrackingData,
}
}),