Flatten fetcher responses

This commit is contained in:
tniezg
2021-09-03 09:52:59 +02:00
parent b9f8ed659d
commit 60894d32c5
15 changed files with 88 additions and 83 deletions

View File

@@ -71,14 +71,12 @@ export default function getAllProductPathsOperation({
const config = commerce.getConfig(userConfig)
const { fetch: apiFetch } = config // TODO: Send config.locale to Spree.
const {
data: { data: spreeSuccessResponse },
} = await apiFetch<{ data: IProductsSlugs }, SpreeSdkVariables>(
'__UNUSED__',
{
variables,
}
)
const { data: spreeSuccessResponse } = await apiFetch<
IProductsSlugs,
SpreeSdkVariables
>('__UNUSED__', {
variables,
})
const normalizedProductsPaths: Pick<Product, 'path'>[] =
spreeSuccessResponse.data.map((spreeProduct) => ({

View File

@@ -57,9 +57,10 @@ export default function getAllProductsOperation({
const config = commerce.getConfig(userConfig)
const { fetch: apiFetch } = config // TODO: Send config.locale to Spree.
const {
data: { data: spreeSuccessResponse },
} = await apiFetch<{ data: IProducts }, SpreeSdkVariables>('__UNUSED__', {
const { data: spreeSuccessResponse } = await apiFetch<
IProducts,
SpreeSdkVariables
>('__UNUSED__', {
variables,
})

View File

@@ -63,9 +63,10 @@ export default function getProductOperation({
const config = commerce.getConfig(userConfig)
const { fetch: apiFetch } = config // TODO: Send config.locale to Spree.
const {
data: { data: spreeSuccessResponse },
} = await apiFetch<{ data: IProduct }, SpreeSdkVariables>('__UNUSED__', {
const { data: spreeSuccessResponse } = await apiFetch<
IProduct,
SpreeSdkVariables
>('__UNUSED__', {
variables,
})

View File

@@ -82,12 +82,8 @@ export default function getSiteInfoOperation({
const config = commerce.getConfig(userConfig)
const { fetch: apiFetch } = config // TODO: Send config.locale to Spree.
const {
data: { data: spreeCategoriesSuccessResponse },
} = await apiFetch<
{
data: ITaxons
},
const { data: spreeCategoriesSuccessResponse } = await apiFetch<
ITaxons,
SpreeSdkVariables
>('__UNUSED__', {
variables: createVariables(
@@ -95,12 +91,8 @@ export default function getSiteInfoOperation({
),
})
const {
data: { data: spreeBrandsSuccessResponse },
} = await apiFetch<
{
data: ITaxons
},
const { data: spreeBrandsSuccessResponse } = await apiFetch<
ITaxons,
SpreeSdkVariables
>('__UNUSED__', {
variables: createVariables(