This commit is contained in:
Belen Curcio
2021-01-11 14:13:29 -03:00
parent 8f9bbe19ca
commit dccc5ef430
4 changed files with 34 additions and 20 deletions

View File

@@ -13,16 +13,25 @@ export function normalizeProduct(productNode: BCProduct): Product {
return {
path,
slug: path?.slice(1, -1),
images: images?.edges?.map(
({ node: { urlOriginal, altText, ...rest } }: any) => ({
url: urlOriginal,
alt: altText,
...rest,
})
),
variants: variants?.edges?.map(({ node }: any) => node),
productOptions: productOptions?.edges?.map(({ node }: any) => node),
slug: path?.replace(/^\/+|\/+$/g, ''),
images: images.edges
? images.edges.map(
({ node: { urlOriginal, altText, ...rest } }: any) => ({
url: urlOriginal,
alt: altText,
...rest,
})
)
: [],
variants: variants.edges
? variants.edges.map(({ node: { entityId, ...rest } }: any) => ({
id: entityId,
...rest,
}))
: [],
productOptions: productOptions.edges
? productOptions.edges.map(({ node }: any) => node)
: [],
price: {
value: prices?.price.value,
currencyCode: prices?.price.currencyCode,

View File

@@ -8,8 +8,8 @@ interface Product extends Entity {
description: string
slug: string
path?: string
images: ProductImage[] | any[] | undefined
variants: ProductVariant[] | any[] | null | undefined
images: ProductImage[]
variants: ProductVariant[]
price: ProductPrice
}
interface ProductImage {