4
0
forked from crowetic/commerce

Update ordercloud types (#532)

This commit is contained in:
Gonzalo Pozzo 2021-10-15 14:29:04 -03:00 committed by GitHub
parent 55b917489d
commit e3471db3eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 14 deletions

View File

@ -1,5 +1,4 @@
import { normalize as normalizeProduct } from '@framework/utils/product'
import { normalize as normalizeProduct } from '../../../../utils/product'
import { ProductsEndpoint } from '.'
// Get products for the product list page. Search and category filter implemented. Sort and brand filter not implemented.
@ -12,28 +11,27 @@ const getProducts: ProductsEndpoint['handlers']['getProducts'] = async ({
//Use a dummy base as we only care about the relative path
const url = new URL('/me/products', 'http://a')
if (search) {
url.searchParams.set('search', search)
if (search) {
url.searchParams.set('search', search)
}
if (categoryId) {
url.searchParams.set('categoryID', String(categoryId))
url.searchParams.set('categoryID', String(categoryId))
}
// Get token from cookies
const token = req.cookies[tokenCookie];
const token = req.cookies[tokenCookie]
var rawProducts = await restBuyerFetch(
'GET',
url.pathname + url.search,
null,
{ token }
);
)
const products = rawProducts.Items.map(normalizeProduct);
const found = rawProducts?.Items?.length > 0;
const products = rawProducts.Items.map(normalizeProduct)
const found = rawProducts?.Items?.length > 0
res.status(200).json({ data: { products, found } })
}
export default getProducts

View File

@ -1,7 +1,8 @@
import { createEndpoint, GetAPISchema } from "@commerce/api"
import { ProductsSchema } from "@commerce/types/product"
import { OrdercloudAPI } from "@framework/api"
import getProducts from "./get-products";
import type { OrdercloudAPI } from '../../../../api'
import { createEndpoint, GetAPISchema } from '@commerce/api'
import { ProductsSchema } from '@commerce/types/product'
import getProducts from './get-products'
import productsEndpoint from '@commerce/api/endpoints/catalog/products'
export type ProductsAPI = GetAPISchema<OrdercloudAPI, ProductsSchema>