4
0
forked from crowetic/commerce

Fixed type

This commit is contained in:
Luis Alvarez 2020-10-21 15:21:31 -05:00
parent 1569d62902
commit 316801627b
3 changed files with 49 additions and 36 deletions

View File

@ -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)

View File

@ -20,6 +20,8 @@ export default async function fetchGraphqlApi<Q, V = any>(
}),
})
// 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<Q, V = any>(
}
return json.data
}
function getRawHeaders(res: Response) {
const headers: { [key: string]: string } = {}
res.headers.forEach((value, key) => {
headers[key] = value
})
return headers
}

View File

@ -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
}