4
0
forked from crowetic/commerce

Minor fixes

This commit is contained in:
Luis Alvarez 2020-10-19 11:30:49 -05:00
parent 9c1372acb7
commit 5bf93038c2
2 changed files with 13 additions and 14 deletions

View File

@ -53,6 +53,13 @@ export type GetAllProductsResult<
T extends Record<keyof GetAllProductsResult, any[]> = { products: Products }
> = T
const FIELDS = [
'products',
'featuredProducts',
'bestSellingProducts',
'newestProducts',
]
export type ProductTypes =
| 'products'
| 'featuredProducts'
@ -92,21 +99,14 @@ async function getAllProducts({
...vars,
}
switch (field) {
case 'products':
variables.products = true
break
case 'featuredProducts':
variables.featuredProducts = true
break
case 'bestSellingProducts':
variables.bestSellingProducts = true
break
case 'newestProducts':
variables.newestProducts = true
break
if (!FIELDS.includes(field)) {
throw new Error(
`The field variable has to match one of ${FIELDS.join(', ')}`
)
}
variables[field] = true
// RecursivePartial forces the method to check for every prop in the data, which is
// required in case there's a custom `query`
const data = await config.fetch<RecursivePartial<GetAllProductsQuery>>(

View File

@ -1,4 +1,3 @@
import { BigcommerceApiError } from '../../utils/errors'
import type { Wishlist, WishlistHandlers } from '..'
// Return wishlist info