mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 11:11:24 +00:00
refactor: adjust the types
This commit is contained in:
@@ -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}`,
|
||||
|
@@ -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}`,
|
||||
},
|
||||
|
@@ -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)
|
||||
) ?? []
|
||||
|
||||
|
@@ -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,
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user