mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
initial provider (#2)
This commit is contained in:
committed by
GitHub
parent
5b4d1b57d4
commit
3342d9d1bb
35
framework/medusa/api/operations/get-all-product-paths.ts
Normal file
35
framework/medusa/api/operations/get-all-product-paths.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
import { Product } from '@commerce/types/product'
|
||||
import { Product as MedusaProduct } from '@medusajs/medusa-js/lib/types'
|
||||
import { MedusaConfig } from '..'
|
||||
|
||||
export type GetAllProductPathsResult = {
|
||||
products: Array<{ path: string }>
|
||||
}
|
||||
|
||||
export default function getAllProductPathsOperation({
|
||||
commerce,
|
||||
}: OperationContext<any>) {
|
||||
async function getAllProductsPaths({
|
||||
config: cfg,
|
||||
}: {
|
||||
config?: Partial<MedusaConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<{ products: Product[] | any[] }> {
|
||||
const config = commerce.getConfig(cfg)
|
||||
|
||||
const results = await config.fetch('products', 'list', {})
|
||||
|
||||
const productHandles = results.data?.products
|
||||
? results.data.products.map(({ handle }: MedusaProduct) => ({
|
||||
path: `/${handle}`,
|
||||
}))
|
||||
: []
|
||||
|
||||
return {
|
||||
products: productHandles,
|
||||
}
|
||||
}
|
||||
|
||||
return getAllProductsPaths
|
||||
}
|
Reference in New Issue
Block a user