mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 06:56:59 +00:00
create get-product operation
This commit is contained in:
parent
5e9300af5f
commit
ad12c23ab2
@ -2,6 +2,7 @@ import type { SyliusConfig } from '../index'
|
|||||||
import { Product } from '@vercel/commerce/types/product'
|
import { Product } from '@vercel/commerce/types/product'
|
||||||
import { GetProductOperation } from '@vercel/commerce/types/product'
|
import { GetProductOperation } from '@vercel/commerce/types/product'
|
||||||
import type { OperationContext } from '@vercel/commerce/api/operations'
|
import type { OperationContext } from '@vercel/commerce/api/operations'
|
||||||
|
import { normalizeProduct } from '../../utils/normalize'
|
||||||
|
|
||||||
export default function getProductOperation({
|
export default function getProductOperation({
|
||||||
commerce,
|
commerce,
|
||||||
@ -9,15 +10,22 @@ export default function getProductOperation({
|
|||||||
async function getProduct<T extends GetProductOperation>({
|
async function getProduct<T extends GetProductOperation>({
|
||||||
query = '',
|
query = '',
|
||||||
variables,
|
variables,
|
||||||
config,
|
config: cfg,
|
||||||
}: {
|
}: {
|
||||||
query?: string
|
query?: string
|
||||||
variables?: T['variables']
|
variables?: T['variables']
|
||||||
config?: Partial<SyliusConfig>
|
config?: Partial<SyliusConfig>
|
||||||
preview?: boolean
|
preview?: boolean
|
||||||
} = {}): Promise<Product | {} | any> {
|
} = {}): Promise<Product | {} | any> {
|
||||||
|
const config = commerce.getConfig(cfg)
|
||||||
|
const syliusProduct = await config.fetch(
|
||||||
|
'GET',
|
||||||
|
`/products-by-slug/${variables!.slug}`
|
||||||
|
)
|
||||||
|
const product = normalizeProduct(syliusProduct)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
product: {},
|
product,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user