refactor: getCollections

This commit is contained in:
Victor Gerbrands 2023-05-04 14:17:43 +02:00
parent 692ef9d8df
commit 18ce43d0a4

View File

@ -312,14 +312,12 @@ export async function getCollectionProducts(handle: string): Promise<Product[]>
export async function getCollections(): Promise<ProductCollection[]> { export async function getCollections(): Promise<ProductCollection[]> {
const res = await medusaRequest('GET', '/collections'); const res = await medusaRequest('GET', '/collections');
const collections: ProductCollection[] = res.body.collections.map( // Reshape collections and hide collections starting with 'hidden'
(collection: MedusaProductCollection) => reshapeCollection(collection) const collections = res.body.collections
); .map((collection: MedusaProductCollection) => reshapeCollection(collection))
.filter((collection: MedusaProductCollection) => !collection.handle.startsWith('hidden'));
// Hide collections starting with 'hidden' return collections;
const filtered = collections.filter((collection) => !collection.handle.startsWith('hidden'));
return filtered;
} }
export async function getProduct(handle: string): Promise<Product> { export async function getProduct(handle: string): Promise<Product> {