mirror of
https://github.com/vercel/commerce.git
synced 2025-06-09 01:36:57 +00:00
refactor: remove unnecessary return in normalizer
This commit is contained in:
parent
4b357bdf2f
commit
1248984f29
@ -1,10 +1,11 @@
|
|||||||
import { Customer } from '@vercel/commerce/types/customer'
|
import { Customer } from '@vercel/commerce/types/customer'
|
||||||
|
import { SyliusCustomer } from 'types/customer'
|
||||||
|
|
||||||
//customer has no type in commerce - SyliusCustomer type is defined in types/customer.ts
|
//customer has no type in commerce - SyliusCustomer type is defined in types/customer.ts
|
||||||
export const normalizeCustomer = (syliusCustomer: any): Customer => {
|
export const normalizeCustomer = (
|
||||||
return {
|
syliusCustomer: SyliusCustomer
|
||||||
firstName: syliusCustomer.firstName,
|
): Customer => ({
|
||||||
lastName: syliusCustomer.lastName,
|
firstName: syliusCustomer.firstName,
|
||||||
email: syliusCustomer.email,
|
lastName: syliusCustomer.lastName,
|
||||||
}
|
email: syliusCustomer.email,
|
||||||
}
|
})
|
||||||
|
@ -14,25 +14,23 @@ import {
|
|||||||
SyliusProductVariant,
|
SyliusProductVariant,
|
||||||
} from '../../types/products'
|
} from '../../types/products'
|
||||||
|
|
||||||
export const normalizeProduct = (product: SyliusProduct): Product => {
|
export const normalizeProduct = (product: SyliusProduct): Product => ({
|
||||||
return {
|
id: product.id.toString(),
|
||||||
id: product.id.toString(),
|
name: product.name,
|
||||||
name: product.name,
|
description: product.shortDescription,
|
||||||
description: product.shortDescription,
|
descriptionHtml: product.description,
|
||||||
descriptionHtml: product.description,
|
slug: product.slug,
|
||||||
slug: product.slug,
|
path: `/${product.slug}`,
|
||||||
path: `/${product.slug}`,
|
images: product.images.map((image) => normalizeProductImage(image)),
|
||||||
images: product.images.map((image) => normalizeProductImage(image)),
|
variants: product.variants.map((variant) =>
|
||||||
variants: product.variants.map((variant) =>
|
normalizeProductVariant(variant, product.options)
|
||||||
normalizeProductVariant(variant, product.options)
|
),
|
||||||
),
|
price: normalizeProductPrice(
|
||||||
price: normalizeProductPrice(
|
product.variants[0].price,
|
||||||
product.variants[0].price,
|
product.variants[0].originalPrice
|
||||||
product.variants[0].originalPrice
|
),
|
||||||
),
|
options: product.options.map((option) => normalizeProductOption(option)),
|
||||||
options: product.options.map((option) => normalizeProductOption(option)),
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizeProductVariant = (
|
const normalizeProductVariant = (
|
||||||
variant: SyliusProductVariant,
|
variant: SyliusProductVariant,
|
||||||
@ -93,16 +91,15 @@ const normalizeProductVariantOption = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalizeProductOption = (option: SyliusProductOption): ProductOption => {
|
const normalizeProductOption = (
|
||||||
return {
|
option: SyliusProductOption
|
||||||
__typename: 'MultipleChoiceOption',
|
): ProductOption => ({
|
||||||
id: option.id.toString(),
|
id: option.id.toString(),
|
||||||
displayName: option.name,
|
displayName: option.name,
|
||||||
values: option.values.map((optionValue) =>
|
values: option.values.map((optionValue) =>
|
||||||
normalizeProductOptionValue(optionValue)
|
normalizeProductOptionValue(optionValue)
|
||||||
),
|
),
|
||||||
}
|
})
|
||||||
}
|
|
||||||
|
|
||||||
const normalizeProductOptionValue = (
|
const normalizeProductOptionValue = (
|
||||||
optionValue: SyliusProductOptionValue
|
optionValue: SyliusProductOptionValue
|
||||||
@ -112,21 +109,15 @@ const normalizeProductOptionValue = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const normalizeProductImage = (
|
const normalizeProductImage = (image: SyliusProductImage): ProductImage => ({
|
||||||
image: SyliusProductImage
|
url: process.env.NEXT_PUBLIC_SYLIUS_ALLOWED_IMAGE_URL + image.path,
|
||||||
): ProductImage => {
|
})
|
||||||
return {
|
|
||||||
url: process.env.NEXT_PUBLIC_SYLIUS_API_URL + image.path,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizeProductPrice = (
|
const normalizeProductPrice = (
|
||||||
price: number,
|
price: number,
|
||||||
originalPrice: number
|
originalPrice: number
|
||||||
): ProductPrice => {
|
): ProductPrice => ({
|
||||||
return {
|
value: originalPrice / 100,
|
||||||
value: originalPrice / 100,
|
salePrice: price / 100,
|
||||||
salePrice: price / 100,
|
currencyCode: 'EUR',
|
||||||
currencyCode: 'EUR',
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
import { SyliusCategorie } from 'types/site'
|
import { SyliusCategorie } from 'types/site'
|
||||||
|
|
||||||
export const normalizeCategorie = (categorie: SyliusCategorie) => {
|
export const normalizeCategorie = (categorie: SyliusCategorie) => ({
|
||||||
return {
|
//We use the code as id because Sylius need the code in the request parameter to filter products
|
||||||
//We use the code as id because Sylius need the code in the request parameter to filter products
|
id: categorie.code,
|
||||||
id: categorie.code,
|
name: categorie.name,
|
||||||
name: categorie.name,
|
slug: categorie.code,
|
||||||
slug: categorie.code,
|
path: `/${categorie.code}`,
|
||||||
path: `/${categorie.code}`,
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user