resolved issues caused by using unreleased medusa-js version

This commit is contained in:
Kasper 2021-09-14 19:41:33 +02:00
parent b44aca9986
commit dc218c14ca
4 changed files with 114 additions and 8 deletions

View File

@ -21,8 +21,8 @@ export default function getProductOperation({
const response = await config.fetch('products', 'list', {}) const response = await config.fetch('products', 'list', {})
if (response.data?.products) { if (response.products) {
const products: MedusaProduct[] = response.data.products const products: MedusaProduct[] = response.products
const product = products const product = products
? products.find(({ handle }) => handle === variables!.slug) ? products.find(({ handle }) => handle === variables!.slug)
: null : null

View File

@ -90,7 +90,7 @@ export interface MedusaProductVariant {
title: string title: string
product_id: string product_id: string
product: MedusaProduct product: MedusaProduct
prices: MedusaMoneyAmount prices: MedusaMoneyAmount[]
sku?: string sku?: string
barcase?: string barcase?: string
ean?: string ean?: string

View File

@ -265,6 +265,37 @@ export const callMedusa = async (
return await medusa.customers.update(customer_id, payload) return await medusa.customers.update(customer_id, payload)
} }
case 'orders':
if (method === 'lookupOrder') {
const { payload } = variables
if (!payload) {
throw new CommerceError({
message: 'An argument for payload is required',
})
}
return await medusa.orders.lookupOrder(payload)
} else if (method === 'retrieve') {
const { order_id } = variables
if (!order_id) {
throw new CommerceError({
message: 'An argument for order_id is required',
})
}
return await medusa.orders.retrieve(order_id)
} else if (method === 'retrieveByCartId') {
const { cart_id } = variables
if (!cart_id) {
throw new CommerceError({
message: 'An argument for cart_id is required',
})
}
return await medusa.orders.retrieveByCartId(cart_id)
}
case 'products': case 'products':
if (method === 'variantsList') { if (method === 'variantsList') {
const { params } = variables const { params } = variables
@ -319,6 +350,81 @@ export const callMedusa = async (
message: 'No valid method argument was provided', message: 'No valid method argument was provided',
}) })
} }
case 'returnReasons':
if (method === 'list') {
return await medusa.returnReasons.list()
} else {
throw new CommerceError({
message: 'No valid method argument was provided',
})
}
case 'returns':
if (method === 'create') {
const { payload } = variables
if (!payload) {
throw new CommerceError({
message: 'An argument for payload is required',
})
}
return await medusa.returns.create(payload)
} else {
throw new CommerceError({
message: 'No valid method argument was provided',
})
}
case 'shippingOptions':
if (method === 'list') {
const { cart_id } = variables
if (!cart_id) {
throw new CommerceError({
message: 'An argument for cart_id is required',
})
}
return await medusa.shippingOptions.list(cart_id)
} else if (method === 'create') {
const { cart_id } = variables
if (!cart_id) {
throw new CommerceError({
message: 'An argument for cart_id is required',
})
}
return await medusa.shippingOptions.listCartOptions(cart_id)
} else {
throw new CommerceError({
message: 'No valid method argument was provided',
})
}
case 'swaps':
if (method === 'create') {
const { cart_id } = variables
if (!cart_id) {
throw new CommerceError({
message: 'An argument for cart_id is required',
})
}
return await medusa.swaps.create({ cart_id })
} else if (method === 'retrieve') {
const { cart_id } = variables
if (!cart_id) {
throw new CommerceError({
message: 'An argument for cart_id is required',
})
}
return await medusa.swaps.retrieve(cart_id)
} else {
throw new CommerceError({
message: 'No valid method argument was provided',
})
}
default: default:
throw new CommerceError({ throw new CommerceError({
message: 'No valid query argument was provided', message: 'No valid query argument was provided',

View File

@ -78,11 +78,11 @@ export function normalizeProduct({
handle: slug, handle: slug,
thumbnail, thumbnail,
}: MedusaProduct): Product { }: MedusaProduct): Product {
const tmpVariant = medusaVariants.reduce((prev, curr) => // const tmpVariant = medusaVariants.reduce((prev, curr) =>
prev.prices.amount < curr.prices.amount ? prev : curr // prev.prices.amount < curr.prices.amount ? prev : curr
) // )
const minPrice = normalizePrice(tmpVariant.prices[0]) //need to fix typing in medusa types // const minPrice = normalizePrice(tmpVariant.prices) //need to fix typing in medusa types
return { return {
id, id,
@ -91,7 +91,7 @@ export function normalizeProduct({
variants: normalizeProductVariants(medusaVariants), variants: normalizeProductVariants(medusaVariants),
images: thumbnail && !images.length ? [{ url: thumbnail }] : images, images: thumbnail && !images.length ? [{ url: thumbnail }] : images,
options: normalizeOptions(medusaOptions), options: normalizeOptions(medusaOptions),
price: minPrice, price: normalizePrice(medusaVariants[0].prices[0]),
path: `/${slug}`, path: `/${slug}`,
slug, slug,
} }