From aa65a9bad9ff7d1a9d6932860f8a2db91aaff10f Mon Sep 17 00:00:00 2001 From: Loan Laux Date: Tue, 6 Jul 2021 18:43:36 +0300 Subject: [PATCH] refactor catalog products API method Signed-off-by: Loan Laux --- .../catalog/{products => }/get-products.ts | 10 +++++++--- .../catalog/{products/index.ts => products.ts} | 0 pages/api/catalog/products.ts | 2 +- yarn.lock | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) rename framework/reactioncommerce/api/endpoints/catalog/{products => }/get-products.ts (65%) rename framework/reactioncommerce/api/endpoints/catalog/{products/index.ts => products.ts} (100%) diff --git a/framework/reactioncommerce/api/endpoints/catalog/products/get-products.ts b/framework/reactioncommerce/api/endpoints/catalog/get-products.ts similarity index 65% rename from framework/reactioncommerce/api/endpoints/catalog/products/get-products.ts rename to framework/reactioncommerce/api/endpoints/catalog/get-products.ts index 4907a096b..a97a8ea50 100644 --- a/framework/reactioncommerce/api/endpoints/catalog/products/get-products.ts +++ b/framework/reactioncommerce/api/endpoints/catalog/get-products.ts @@ -1,6 +1,6 @@ import catalogItemsQuery from '@framework/utils/queries/catalog-items-query' import { normalizeProduct } from '@framework/utils' -import type { ProductsEndpoint } from '.' +import type { ProductsEndpoint } from './products' const getCart: ProductsEndpoint['handlers']['getProducts'] = async ({ req, @@ -15,9 +15,13 @@ const getCart: ProductsEndpoint['handlers']['getProducts'] = async ({ }, }) - const products = catalogItems.map((item) => normalizeProduct(item)) + const products = catalogItems?.edges?.map(({ node }) => normalizeProduct(node)) - res.status(200).json({ data: products ?? null }) + res.status(200).json({ + data: { + products: products ?? null + } + }) } export default getCart diff --git a/framework/reactioncommerce/api/endpoints/catalog/products/index.ts b/framework/reactioncommerce/api/endpoints/catalog/products.ts similarity index 100% rename from framework/reactioncommerce/api/endpoints/catalog/products/index.ts rename to framework/reactioncommerce/api/endpoints/catalog/products.ts diff --git a/pages/api/catalog/products.ts b/pages/api/catalog/products.ts index 5f2be15a2..631bfd516 100644 --- a/pages/api/catalog/products.ts +++ b/pages/api/catalog/products.ts @@ -1,4 +1,4 @@ -import productsApi from '@framework/api/endpoints/catalog/get-products' +import productsApi from '@framework/api/endpoints/catalog/products' import commerce from '@lib/api/commerce' export default productsApi(commerce) diff --git a/yarn.lock b/yarn.lock index 8d1a534a5..62b7698cd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1140,6 +1140,11 @@ resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.1.tgz#18845205e86ff0038517aab7a18a62a6b9f71275" integrity sha512-EaCxbanVeyxDRTQBkdLb3Bvl/HK7PBK6UJjsSixB0iHKoWxE5uu2Q/DgtpOhPIojN0Zl1whvOd7PoHs2P0s5eA== +"@types/uuid@8.3.1": + version "8.3.1" + resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.1.tgz#1a32969cf8f0364b3d8c8af9cc3555b7805df14f" + integrity sha512-Y2mHTRAbqfFkpjldbkHGY8JIzRN6XqYRliG8/24FcHm2D2PwW24fl5xMRTVGdrb7iMrwCaIEbLWerGIkXuFWVg== + "@types/websocket@1.0.2": version "1.0.2" resolved "https://registry.yarnpkg.com/@types/websocket/-/websocket-1.0.2.tgz#d2855c6a312b7da73ed16ba6781815bf30c6187a" @@ -6044,6 +6049,19 @@ util@^0.12.0: safe-buffer "^5.1.2" which-typed-array "^1.1.2" +uuid@8.3.2: + version "8.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== + +uuidv4@^6.2.10: + version "6.2.11" + resolved "https://registry.yarnpkg.com/uuidv4/-/uuidv4-6.2.11.tgz#34d5a03324eb38296b87ae523a64233b5286cc27" + integrity sha512-OTS4waH9KplrXNADKo+Q1kT9AHWr8DaC0S5F54RQzEwcUaEzBEWQQlJyDUw/u1bkRhJyqkqhLD4M4lbFbV+89g== + dependencies: + "@types/uuid" "8.3.1" + uuid "8.3.2" + valid-url@1.0.9, valid-url@^1.0.9: version "1.0.9" resolved "https://registry.yarnpkg.com/valid-url/-/valid-url-1.0.9.tgz#1c14479b40f1397a75782f115e4086447433a200"