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 { SyliusCustomer } from 'types/customer'
|
||||
|
||||
//customer has no type in commerce - SyliusCustomer type is defined in types/customer.ts
|
||||
export const normalizeCustomer = (syliusCustomer: any): Customer => {
|
||||
return {
|
||||
export const normalizeCustomer = (
|
||||
syliusCustomer: SyliusCustomer
|
||||
): Customer => ({
|
||||
firstName: syliusCustomer.firstName,
|
||||
lastName: syliusCustomer.lastName,
|
||||
email: syliusCustomer.email,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -14,8 +14,7 @@ import {
|
||||
SyliusProductVariant,
|
||||
} from '../../types/products'
|
||||
|
||||
export const normalizeProduct = (product: SyliusProduct): Product => {
|
||||
return {
|
||||
export const normalizeProduct = (product: SyliusProduct): Product => ({
|
||||
id: product.id.toString(),
|
||||
name: product.name,
|
||||
description: product.shortDescription,
|
||||
@ -31,8 +30,7 @@ export const normalizeProduct = (product: SyliusProduct): Product => {
|
||||
product.variants[0].originalPrice
|
||||
),
|
||||
options: product.options.map((option) => normalizeProductOption(option)),
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const normalizeProductVariant = (
|
||||
variant: SyliusProductVariant,
|
||||
@ -93,16 +91,15 @@ const normalizeProductVariantOption = (
|
||||
}
|
||||
}
|
||||
|
||||
const normalizeProductOption = (option: SyliusProductOption): ProductOption => {
|
||||
return {
|
||||
__typename: 'MultipleChoiceOption',
|
||||
const normalizeProductOption = (
|
||||
option: SyliusProductOption
|
||||
): ProductOption => ({
|
||||
id: option.id.toString(),
|
||||
displayName: option.name,
|
||||
values: option.values.map((optionValue) =>
|
||||
normalizeProductOptionValue(optionValue)
|
||||
),
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const normalizeProductOptionValue = (
|
||||
optionValue: SyliusProductOptionValue
|
||||
@ -112,21 +109,15 @@ const normalizeProductOptionValue = (
|
||||
}
|
||||
}
|
||||
|
||||
export const normalizeProductImage = (
|
||||
image: SyliusProductImage
|
||||
): ProductImage => {
|
||||
return {
|
||||
url: process.env.NEXT_PUBLIC_SYLIUS_API_URL + image.path,
|
||||
}
|
||||
}
|
||||
const normalizeProductImage = (image: SyliusProductImage): ProductImage => ({
|
||||
url: process.env.NEXT_PUBLIC_SYLIUS_ALLOWED_IMAGE_URL + image.path,
|
||||
})
|
||||
|
||||
const normalizeProductPrice = (
|
||||
price: number,
|
||||
originalPrice: number
|
||||
): ProductPrice => {
|
||||
return {
|
||||
): ProductPrice => ({
|
||||
value: originalPrice / 100,
|
||||
salePrice: price / 100,
|
||||
currencyCode: 'EUR',
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -1,11 +1,9 @@
|
||||
import { SyliusCategorie } from 'types/site'
|
||||
|
||||
export const normalizeCategorie = (categorie: SyliusCategorie) => {
|
||||
return {
|
||||
export const normalizeCategorie = (categorie: SyliusCategorie) => ({
|
||||
//We use the code as id because Sylius need the code in the request parameter to filter products
|
||||
id: categorie.code,
|
||||
name: categorie.name,
|
||||
slug: categorie.code,
|
||||
path: `/${categorie.code}`,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user