4
0
forked from crowetic/commerce
Belen Curcio a3a2c15f70 change
2021-01-11 12:26:34 -03:00

34 lines
734 B
TypeScript

export function normalizeProduct(productNode: any): Product {
// console.log(productNode)
const {
node: {
entityId: id,
images,
variants,
productOptions,
prices,
path,
...rest
},
} = productNode
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),
price: {
value: prices?.price.value,
currencyCode: prices?.price.currencyCode,
},
...rest,
}
}