From 18ce43d0a4eca1ac6171cf656436aac1f6cf4b6f Mon Sep 17 00:00:00 2001 From: Victor Gerbrands Date: Thu, 4 May 2023 14:17:43 +0200 Subject: [PATCH] refactor: getCollections --- lib/medusa/index.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/medusa/index.ts b/lib/medusa/index.ts index 8f511006e..186bd825c 100644 --- a/lib/medusa/index.ts +++ b/lib/medusa/index.ts @@ -312,14 +312,12 @@ export async function getCollectionProducts(handle: string): Promise export async function getCollections(): Promise { const res = await medusaRequest('GET', '/collections'); - const collections: ProductCollection[] = res.body.collections.map( - (collection: MedusaProductCollection) => reshapeCollection(collection) - ); + // Reshape collections and hide collections starting with 'hidden' + const collections = res.body.collections + .map((collection: MedusaProductCollection) => reshapeCollection(collection)) + .filter((collection: MedusaProductCollection) => !collection.handle.startsWith('hidden')); - // Hide collections starting with 'hidden' - const filtered = collections.filter((collection) => !collection.handle.startsWith('hidden')); - - return filtered; + return collections; } export async function getProduct(handle: string): Promise {