Updated types

This commit is contained in:
cond0r
2021-02-18 15:49:44 +02:00
parent 89cc3d0608
commit ce5fcb6975
4 changed files with 47 additions and 46 deletions

View File

@@ -1,14 +1,26 @@
import { Cart } from '@commerce/types'
import { ValidationError } from '@commerce/utils/errors'
import { normalizeCart } from '@framework/utils/normalize'
import { Checkout, UserError } from '@framework/schema'
import { CommerceError, ValidationError } from '@commerce/utils/errors'
const checkoutToCart = (checkoutResponse: {
checkout: Checkout
userErrors?: UserError[]
}): Cart => {
const checkout = checkoutResponse?.checkout
const userErrors = checkoutResponse?.userErrors
import {
CheckoutLineItemsAddPayload,
CheckoutLineItemsUpdatePayload,
Maybe,
} from '@framework/schema'
import { normalizeCart } from '@framework/utils'
export type CheckoutPayload =
| CheckoutLineItemsAddPayload
| CheckoutLineItemsUpdatePayload
const checkoutToCart = (checkoutPayload?: Maybe<CheckoutPayload>): Cart => {
if (!checkoutPayload || !checkoutPayload?.checkout) {
throw new CommerceError({
message: 'Invalid response from Shopify',
})
}
const checkout = checkoutPayload?.checkout
const userErrors = checkoutPayload?.userErrors
if (userErrors && userErrors.length) {
throw new ValidationError({