changed list products so it does not rely on unreleased version of medusa-js

This commit is contained in:
Kasper
2021-09-14 18:55:07 +02:00
parent 4a48e40aca
commit 739e2730e6
4 changed files with 35 additions and 17 deletions

View File

@@ -1,6 +1,8 @@
import { CommerceError } from '@commerce/utils/errors'
import { MEDUSA_PUBLIC_STORE_URL } from '@framework/const'
import medusa from '../medusa'
import fetch from 'node-fetch'
import axios from 'axios'
export const callMedusa = async (
method: string,
@@ -313,13 +315,28 @@ export const callMedusa = async (
return await medusa.products.variants.retrieve(variant_id)
} else if (method === 'list') {
const { query } = variables
let path = '/store/products'
return await medusa.products.list(
query && {
limit: query.limit || null,
offset: query.offset || null,
if (query) {
const formattedQuery = {
offset: query.offset || 0,
limit: query.limit || 100,
}
)
const queryString = Object.entries(formattedQuery).map(
([key, value]) => {
return `${key}=${value}`
}
)
path = `/store/products?${queryString.join('&')}`
}
const res = await fetch(`${MEDUSA_PUBLIC_STORE_URL}${path}`, {
method: 'GET',
})
return await res.json()
} else if (method === 'retrieve') {
const { product_id } = variables