Skip to content

Commit

Permalink
feat(cart)!: change actions to implement DaffCartRetrievalAction an…
Browse files Browse the repository at this point in the history
…d `DaffFailureAction` (#2636)

BREAKING CHANGE: failure actions' payload type has changed from `DaffStateError` to `DaffStateError[]`
  • Loading branch information
griest024 committed Dec 1, 2023
1 parent 5a75c56 commit bd968f7
Show file tree
Hide file tree
Showing 68 changed files with 430 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('DaffAuthorizeNetEffects', () => {
const authorizeNetUpdatePayment = new DaffAuthorizeNetUpdatePayment(paymentTokenRequest, stubAddress);
const mockCode = 'code';
const mockErrorMessage = 'Cart payment with billing update failed.';
const cartPaymentUpdateWithBillingFailure = new DaffCartPaymentUpdateWithBillingFailure({ code: mockCode, recoverable: false, message: mockErrorMessage });
const cartPaymentUpdateWithBillingFailure = new DaffCartPaymentUpdateWithBillingFailure([{ code: mockCode, recoverable: false, message: mockErrorMessage }]);
const authorizeNetPaymentUpdateFailure = new DaffAuthorizeNetUpdatePaymentFailure({
code: mockCode,
recoverable: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class DaffAuthorizeNetEffects<T extends DaffAuthorizeNetTokenRequest = Da
DaffCartPaymentActionTypes.CartPaymentUpdateWithBillingSuccessAction,
),
map(([updatePaymentAction, updatePaymentFailureAction]: [DaffAuthorizeNetUpdatePayment, DaffCartPaymentUpdateWithBillingFailure]) =>
new DaffAuthorizeNetUpdatePaymentFailure(this.errorMatcher(updatePaymentFailureAction.payload)),
new DaffAuthorizeNetUpdatePaymentFailure(this.errorMatcher(updatePaymentFailureAction.payload[0])),
),
));

Expand Down
64 changes: 32 additions & 32 deletions libs/cart-customer/state/src/effects/unauthorized.effects.spec.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class DaffCartCustomerUnauthorizedEffects {
DaffCartOrderActionTypes.CartPlaceOrderFailureAction,
),
filter((action) =>
action.payload.code === DaffCartDriverErrorCodes.UNAUTHORIZED_FOR_CART,
!!action.payload.find(({ code }) => code === DaffCartDriverErrorCodes.UNAUTHORIZED_FOR_CART),
),
map(() => new DaffAuthCheck()),
));
Expand Down
16 changes: 8 additions & 8 deletions libs/cart-store-credit/state/src/effects/store-credit.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import {
DaffCartStoreCreditDriverInterface,
} from '@daffodil/cart-store-credit/driver';
import {
DaffError,
DaffStorageServiceError,
DAFF_STORAGE_SERVICE_ERROR_CODE,
catchAndArrayifyErrors,
} from '@daffodil/core';
import { ErrorTransformer } from '@daffodil/core/state';

Expand Down Expand Up @@ -59,9 +59,9 @@ export class DaffCartStoreCreditEffects<
defer(() => of(this.storage.getCartId())).pipe(
switchMap((cartId) => this.driver.apply(cartId)),
map(resp => new DaffCartStoreCreditApplySuccess<T>(resp)),
catchError((error: DaffError) => of(error instanceof DaffStorageServiceError
? new DaffCartStorageFailure(this.errorMatcher(error))
: new DaffCartStoreCreditApplyFailure([this.errorMatcher(error)]))),
catchAndArrayifyErrors((error) => of(error.find((err) => err.code === DAFF_STORAGE_SERVICE_ERROR_CODE)
? new DaffCartStorageFailure(error.map(this.errorMatcher))
: new DaffCartStoreCreditApplyFailure(error.map(this.errorMatcher)))),
),
),
));
Expand All @@ -72,9 +72,9 @@ export class DaffCartStoreCreditEffects<
defer(() => of(this.storage.getCartId())).pipe(
switchMap((cartId) => this.driver.remove(cartId)),
map(resp => new DaffCartStoreCreditRemoveSuccess<T>(resp)),
catchError((error: DaffError) => of(error instanceof DaffStorageServiceError
? new DaffCartStorageFailure(this.errorMatcher(error))
: new DaffCartStoreCreditRemoveFailure([this.errorMatcher(error)]))),
catchAndArrayifyErrors((error) => of(error.find((err) => err.code === DAFF_STORAGE_SERVICE_ERROR_CODE)
? new DaffCartStorageFailure(error.map(this.errorMatcher))
: new DaffCartStoreCreditRemoveFailure(error.map(this.errorMatcher)))),
),
),
));
Expand Down
13 changes: 9 additions & 4 deletions libs/cart/state/src/actions/cart-address.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import {
DaffCartAddress,
DaffCart,
} from '@daffodil/cart';
import { DaffStateError } from '@daffodil/core/state';
import {
DaffFailureAction,
DaffStateError,
} from '@daffodil/core/state';

import { DaffCartRetrievalAction } from '../cart-retrieval/public_api';

/**
* An enum for the cart address action types.
Expand All @@ -27,7 +32,7 @@ export class DaffCartAddressUpdate<T extends DaffCartAddress = DaffCartAddress>
/**
* Indicates the successful update of both the shipping and billing address of the cart.
*/
export class DaffCartAddressUpdateSuccess<T extends DaffCart = DaffCart> implements Action {
export class DaffCartAddressUpdateSuccess<T extends DaffCart = DaffCart> implements DaffCartRetrievalAction<T> {
readonly type = DaffCartAddressActionTypes.CartAddressUpdateSuccessAction;

constructor(public payload: Partial<T>) {}
Expand All @@ -36,10 +41,10 @@ export class DaffCartAddressUpdateSuccess<T extends DaffCart = DaffCart> impleme
/**
* Indicates the failed update of either the shipping or billing address of the cart.
*/
export class DaffCartAddressUpdateFailure implements Action {
export class DaffCartAddressUpdateFailure implements DaffFailureAction {
readonly type = DaffCartAddressActionTypes.CartAddressUpdateFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand Down
17 changes: 11 additions & 6 deletions libs/cart/state/src/actions/cart-billing-address.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import {
DaffCartAddress,
DaffCart,
} from '@daffodil/cart';
import { DaffStateError } from '@daffodil/core/state';
import {
DaffFailureAction,
DaffStateError,
} from '@daffodil/core/state';

import { DaffCartRetrievalAction } from '../cart-retrieval/public_api';

/**
* An enum for the cart billing address action types.
Expand Down Expand Up @@ -37,10 +42,10 @@ export class DaffCartBillingAddressLoadSuccess<T extends DaffCartAddress> implem
/**
* Indicates the failed load of the cart's billing address.
*/
export class DaffCartBillingAddressLoadFailure implements Action {
export class DaffCartBillingAddressLoadFailure implements DaffFailureAction {
readonly type = DaffCartBillingAddressActionTypes.CartBillingAddressLoadFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand All @@ -55,7 +60,7 @@ export class DaffCartBillingAddressUpdate<T extends DaffCartAddress = DaffCartAd
/**
* Indicates the successful update of the cart's billing address.
*/
export class DaffCartBillingAddressUpdateSuccess<T extends DaffCart = DaffCart> implements Action {
export class DaffCartBillingAddressUpdateSuccess<T extends DaffCart = DaffCart> implements DaffCartRetrievalAction<T> {
readonly type = DaffCartBillingAddressActionTypes.CartBillingAddressUpdateSuccessAction;

constructor(public payload: Partial<T>) {}
Expand All @@ -64,10 +69,10 @@ export class DaffCartBillingAddressUpdateSuccess<T extends DaffCart = DaffCart>
/**
* Indicates the failed update of the cart's billing address.
*/
export class DaffCartBillingAddressUpdateFailure implements Action {
export class DaffCartBillingAddressUpdateFailure implements DaffFailureAction {
readonly type = DaffCartBillingAddressActionTypes.CartBillingAddressUpdateFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand Down
29 changes: 17 additions & 12 deletions libs/cart/state/src/actions/cart-coupon.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import {
DaffCartCoupon,
DaffCart,
} from '@daffodil/cart';
import { DaffStateError } from '@daffodil/core/state';
import {
DaffFailureAction,
DaffStateError,
} from '@daffodil/core/state';

import { DaffCartRetrievalAction } from '../cart-retrieval/public_api';

/**
* An enum for the cart coupon action types.
Expand Down Expand Up @@ -37,7 +42,7 @@ export class DaffCartCouponApply<T extends DaffCartCoupon = DaffCartCoupon> impl
/**
* Indicates the successful application of a cart coupon.
*/
export class DaffCartCouponApplySuccess<T extends DaffCart = DaffCart> implements Action {
export class DaffCartCouponApplySuccess<T extends DaffCart = DaffCart> implements DaffCartRetrievalAction<T> {
readonly type = DaffCartCouponActionTypes.CartCouponApplySuccessAction;

constructor(public payload: Partial<T>) {}
Expand All @@ -46,10 +51,10 @@ export class DaffCartCouponApplySuccess<T extends DaffCart = DaffCart> implement
/**
* Indicates the failed application of a cart coupon.
*/
export class DaffCartCouponApplyFailure implements Action {
export class DaffCartCouponApplyFailure implements DaffFailureAction {
readonly type = DaffCartCouponActionTypes.CartCouponApplyFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand All @@ -71,10 +76,10 @@ export class DaffCartCouponListSuccess<T extends DaffCartCoupon = DaffCartCoupon
/**
* Indicates the failed load of the cart's coupons.
*/
export class DaffCartCouponListFailure implements Action {
export class DaffCartCouponListFailure implements DaffFailureAction {
readonly type = DaffCartCouponActionTypes.CartCouponListFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand All @@ -89,7 +94,7 @@ export class DaffCartCouponRemove<T extends DaffCartCoupon = DaffCartCoupon> imp
/**
* Indicates the successful removal of a cart coupon.
*/
export class DaffCartCouponRemoveSuccess<T extends DaffCart = DaffCart> implements Action {
export class DaffCartCouponRemoveSuccess<T extends DaffCart = DaffCart> implements DaffCartRetrievalAction<T> {
readonly type = DaffCartCouponActionTypes.CartCouponRemoveSuccessAction;

constructor(public payload: Partial<T>) {}
Expand All @@ -98,10 +103,10 @@ export class DaffCartCouponRemoveSuccess<T extends DaffCart = DaffCart> implemen
/**
* Indicates the failed removal of a cart coupon.
*/
export class DaffCartCouponRemoveFailure implements Action {
export class DaffCartCouponRemoveFailure implements DaffFailureAction {
readonly type = DaffCartCouponActionTypes.CartCouponRemoveFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand All @@ -114,7 +119,7 @@ export class DaffCartCouponRemoveAll implements Action {
/**
* Indicates the successful removal of all of the cart's coupons.
*/
export class DaffCartCouponRemoveAllSuccess<T extends DaffCart = DaffCart> implements Action {
export class DaffCartCouponRemoveAllSuccess<T extends DaffCart = DaffCart> implements DaffCartRetrievalAction<T> {
readonly type = DaffCartCouponActionTypes.CartCouponRemoveAllSuccessAction;

constructor(public payload: Partial<T>) {}
Expand All @@ -123,10 +128,10 @@ export class DaffCartCouponRemoveAllSuccess<T extends DaffCart = DaffCart> imple
/**
* Indicates the failed removal of all of the cart's coupons.
*/
export class DaffCartCouponRemoveAllFailure implements Action {
export class DaffCartCouponRemoveAllFailure implements DaffFailureAction {
readonly type = DaffCartCouponActionTypes.CartCouponRemoveAllFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand Down
26 changes: 15 additions & 11 deletions libs/cart/state/src/actions/cart-item.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import {
DaffCart,
DaffCartItemInput,
} from '@daffodil/cart';
import { DaffStateError } from '@daffodil/core/state';
import {
DaffFailureAction,
DaffStateError,
} from '@daffodil/core/state';

import { DaffCartRetrievalAction } from '../cart-retrieval/public_api';
import { DaffStatefulCartItem } from '../models/public_api';

/**
Expand Down Expand Up @@ -52,10 +56,10 @@ export class DaffCartItemListSuccess<T extends DaffStatefulCartItem = DaffStatef
/**
* Indicates the failed load of the cart's items.
*/
export class DaffCartItemListFailure implements Action {
export class DaffCartItemListFailure implements DaffFailureAction {
readonly type = DaffCartItemActionTypes.CartItemListFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand All @@ -82,7 +86,7 @@ export class DaffCartItemLoadSuccess<T extends DaffStatefulCartItem = DaffStatef
export class DaffCartItemLoadFailure<T extends DaffStatefulCartItem = DaffStatefulCartItem> implements Action {
readonly type = DaffCartItemActionTypes.CartItemLoadFailureAction;

constructor(public payload: DaffStateError, public itemId: T['id']) {}
constructor(public payload: DaffStateError[], public itemId: T['id']) {}
}

/**
Expand Down Expand Up @@ -112,7 +116,7 @@ export class DaffCartItemUpdateSuccess<
export class DaffCartItemUpdateFailure<T extends DaffStatefulCartItem = DaffStatefulCartItem> implements Action {
readonly type = DaffCartItemActionTypes.CartItemUpdateFailureAction;

constructor(public payload: DaffStateError, public itemId: T['id']) {}
constructor(public payload: DaffStateError[], public itemId: T['id']) {}
}

/**
Expand All @@ -127,7 +131,7 @@ export class DaffCartItemAdd<T extends DaffCartItemInput = DaffCartItemInput> im
/**
* Indicates the successful addition of a product to the cart.
*/
export class DaffCartItemAddSuccess<T extends DaffCart = DaffCart> implements Action {
export class DaffCartItemAddSuccess<T extends DaffCart = DaffCart> implements DaffCartRetrievalAction<T> {
readonly type = DaffCartItemActionTypes.CartItemAddSuccessAction;

constructor(public payload: Partial<T>) {}
Expand All @@ -136,10 +140,10 @@ export class DaffCartItemAddSuccess<T extends DaffCart = DaffCart> implements Ac
/**
* Indicates the failed addition of a product to the cart.
*/
export class DaffCartItemAddFailure implements Action {
export class DaffCartItemAddFailure implements DaffFailureAction {
readonly type = DaffCartItemActionTypes.CartItemAddFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand All @@ -166,7 +170,7 @@ export class DaffCartItemDeleteSuccess<T extends DaffCart = DaffCart> implements
export class DaffCartItemDeleteFailure<T extends DaffStatefulCartItem = DaffStatefulCartItem> implements Action {
readonly type = DaffCartItemActionTypes.CartItemDeleteFailureAction;

constructor(public payload: DaffStateError, public itemId: T['id']) {}
constructor(public payload: DaffStateError[], public itemId: T['id']) {}
}

/**
Expand All @@ -188,10 +192,10 @@ export class DaffCartItemDeleteOutOfStockSuccess<T extends DaffCart = DaffCart>
/**
* Indicates the failed deletion of all out of stock cart items.
*/
export class DaffCartItemDeleteOutOfStockFailure implements Action {
export class DaffCartItemDeleteOutOfStockFailure implements DaffFailureAction {
readonly type = DaffCartItemActionTypes.CartItemDeleteOutOfStockFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand Down
9 changes: 6 additions & 3 deletions libs/cart/state/src/actions/cart-order.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
DaffCartPaymentMethod,
DaffCartOrderResult,
} from '@daffodil/cart';
import { DaffStateError } from '@daffodil/core/state';
import {
DaffFailureAction,
DaffStateError,
} from '@daffodil/core/state';

/**
* An enum for the cart order action types.
Expand Down Expand Up @@ -36,10 +39,10 @@ export class DaffCartPlaceOrderSuccess<T extends DaffCartOrderResult = DaffCartO
/**
* Indicates the failed order placement for a cart.
*/
export class DaffCartPlaceOrderFailure implements Action {
export class DaffCartPlaceOrderFailure implements DaffFailureAction {
readonly type = DaffCartOrderActionTypes.CartPlaceOrderFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand Down
9 changes: 6 additions & 3 deletions libs/cart/state/src/actions/cart-payment-methods.actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Action } from '@ngrx/store';

import { DaffCartPaymentMethod } from '@daffodil/cart';
import { DaffStateError } from '@daffodil/core/state';
import {
DaffFailureAction,
DaffStateError,
} from '@daffodil/core/state';

/**
* An enum for the cart payment methods action types.
Expand Down Expand Up @@ -33,10 +36,10 @@ export class DaffCartPaymentMethodsLoadSuccess<T extends DaffCartPaymentMethod =
/**
* Indicates the failed load of the cart's available payment methods.
*/
export class DaffCartPaymentMethodsLoadFailure implements Action {
export class DaffCartPaymentMethodsLoadFailure implements DaffFailureAction {
readonly type = DaffCartPaymentMethodsActionTypes.CartPaymentMethodsLoadFailureAction;

constructor(public payload: DaffStateError) {}
constructor(public payload: DaffStateError[]) {}
}

/**
Expand Down
Loading

0 comments on commit bd968f7

Please sign in to comment.