refactor: adjust the types

This commit is contained in:
Zaiste
2021-04-19 15:36:35 +02:00
parent b5e21a54b3
commit 1e946c8b47
6 changed files with 15 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
import { CollectionEdge } from '../schema'
import { CollectionCountableEdge } from '../schema'
import { getConfig, SaleorConfig } from '../api'
import getAllCollectionsQuery from '../utils/queries/get-all-collections-query'
@@ -14,7 +14,7 @@ const getAllCollections = async (options?: {
const edges = data.collections?.edges ?? []
const categories = edges.map(
({ node: { id: entityId, name, slug } }: CollectionEdge) => ({
({ node: { id: entityId, name, slug } }: CollectionCountableEdge) => ({
entityId,
name,
path: `/${slug}`,

View File

@@ -1,7 +1,7 @@
import { Product } from '@commerce/types'
import { getConfig, SaleorConfig } from '../api'
import fetchAllProducts from '../api/utils/fetch-all-products'
import { ProductEdge } from '../schema'
import { ProductCountableEdge } from '../schema'
import getAllProductsPathsQuery from '../utils/queries/get-all-products-paths-query'
type ProductPath = {
@@ -31,7 +31,7 @@ const getAllProductPaths = async (options?: {
})
return {
products: products?.map(({ node: { handle } }: ProductEdge) => ({
products: products?.map(({ node: { slug } }: ProductCountableEdge) => ({
node: {
path: `/${handle}`,
},

View File

@@ -1,6 +1,6 @@
import { GraphQLFetcherResult } from '@commerce/api'
import { getConfig, SaleorConfig } from '../api'
import { Product as SaleorProduct } from '../schema'
import { ProductCountableEdge } from '../schema'
import { getAllProductsQuery } from '../utils/queries'
import { normalizeProduct } from '../utils/normalize'
import { Product } from '@commerce/types'
@@ -28,7 +28,7 @@ const getAllProducts = async (options: {
)
const products =
data.products?.edges?.map(({ node: p }: SaleorProduct) =>
data.products?.edges?.map(({ node: p }: ProductCountableEdge) =>
normalizeProduct(p)
) ?? []

View File

@@ -1,7 +1,7 @@
import { SWRHook } from '@commerce/utils/types'
import useSearch, { UseSearch } from '@commerce/product/use-search'
import { ProductEdge } from '../schema'
import { ProductCountableEdge } from '../schema'
import {
getAllProductsQuery,
getCollectionProductsQuery,
@@ -57,7 +57,9 @@ export const handler: SWRHook<
}
return {
products: edges.map(({ node }: ProductEdge) => normalizeProduct(node)),
products: edges.map(({ node }: ProductCountableEdge) =>
normalizeProduct(node)
),
found: !!edges.length,
}
},