From 316801627bf1725e04af77c64f2191775c07faa4 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Wed, 21 Oct 2020 15:21:31 -0500 Subject: [PATCH] Fixed type --- .../api/customers/handlers/signup.ts | 64 +++++++++---------- .../api/utils/fetch-graphql-api.ts | 12 ++++ .../wishlist/handlers/get-all-wishlists.ts | 9 +-- 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/lib/bigcommerce/api/customers/handlers/signup.ts b/lib/bigcommerce/api/customers/handlers/signup.ts index 85400e39b..911919088 100644 --- a/lib/bigcommerce/api/customers/handlers/signup.ts +++ b/lib/bigcommerce/api/customers/handlers/signup.ts @@ -20,40 +20,40 @@ const signup: SignupHandlers['signup'] = async ({ let result: { data?: any } = {} - try { - result = await config.storeApiFetch('/v3/customers', { - method: 'POST', - body: JSON.stringify([ - { - first_name: firstName, - last_name: lastName, - email, - authentication: { - new_password: password, - }, - }, - ]), - }) - } catch (error) { - if (error instanceof BigcommerceApiError && error.status === 422) { - const hasEmailError = '0.email' in error.data?.errors + // try { + // result = await config.storeApiFetch('/v3/customers', { + // method: 'POST', + // body: JSON.stringify([ + // { + // first_name: firstName, + // last_name: lastName, + // email, + // authentication: { + // new_password: password, + // }, + // }, + // ]), + // }) + // } catch (error) { + // if (error instanceof BigcommerceApiError && error.status === 422) { + // const hasEmailError = '0.email' in error.data?.errors - // If there's an error with the email, it most likely means it's duplicated - if (hasEmailError) { - return res.status(400).json({ - data: null, - errors: [ - { - message: 'The email is already in use', - code: 'duplicated_email', - }, - ], - }) - } - } + // // If there's an error with the email, it most likely means it's duplicated + // if (hasEmailError) { + // return res.status(400).json({ + // data: null, + // errors: [ + // { + // message: 'The email is already in use', + // code: 'duplicated_email', + // }, + // ], + // }) + // } + // } - throw error - } + // throw error + // } console.log('DATA', result.data) diff --git a/lib/bigcommerce/api/utils/fetch-graphql-api.ts b/lib/bigcommerce/api/utils/fetch-graphql-api.ts index 1e79f7c2f..1ab323832 100644 --- a/lib/bigcommerce/api/utils/fetch-graphql-api.ts +++ b/lib/bigcommerce/api/utils/fetch-graphql-api.ts @@ -20,6 +20,8 @@ export default async function fetchGraphqlApi( }), }) + // console.log('HEADERS', getRawHeaders(res)) + const json = await res.json() if (json.errors) { console.error(json.errors) @@ -27,3 +29,13 @@ export default async function fetchGraphqlApi( } return json.data } + +function getRawHeaders(res: Response) { + const headers: { [key: string]: string } = {} + + res.headers.forEach((value, key) => { + headers[key] = value + }) + + return headers +} diff --git a/lib/bigcommerce/api/wishlist/handlers/get-all-wishlists.ts b/lib/bigcommerce/api/wishlist/handlers/get-all-wishlists.ts index 310c7f41d..30fb83c2f 100644 --- a/lib/bigcommerce/api/wishlist/handlers/get-all-wishlists.ts +++ b/lib/bigcommerce/api/wishlist/handlers/get-all-wishlists.ts @@ -1,5 +1,4 @@ -import { BigcommerceApiError } from '../../utils/errors' -import type { WishlistList, WishlistHandlers } from '..' +import type { Wishlist, WishlistHandlers } from '..' // Return all wishlists const getAllWishlists: WishlistHandlers['getAllWishlists'] = async ({ @@ -7,10 +6,12 @@ const getAllWishlists: WishlistHandlers['getAllWishlists'] = async ({ body: { customerId }, config, }) => { - let result: { data?: WishlistList } = {} + let result: { data?: Wishlist[] } = {} try { - result = await config.storeApiFetch(`/v3/wishlists/customer_id=${customerId}`) + result = await config.storeApiFetch( + `/v3/wishlists/customer_id=${customerId}` + ) } catch (error) { throw error }