-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cart): use operation entity state for item entities
- Loading branch information
Showing
42 changed files
with
566 additions
and
1,947 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { DaffCartItem } from '../models/public_api'; | ||
|
||
/** | ||
* Finds the IDs of any affected cart items between two carts. | ||
*/ | ||
export function daffCartGetAffectedItems<T extends DaffCartItem = DaffCartItem>(oldItems: Array<T>, newItems: Array<T>): Array<T['id']> { | ||
return newItems.reduce((acc, newItem) => { | ||
const oldItem = oldItems.find(({ id }) => id === newItem.id); | ||
if (!oldItem || oldItem.qty !== newItem.qty) { | ||
acc.push(newItem.id); | ||
} | ||
return acc; | ||
}, <Array<T['id']>>[]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
DaffCartItem, | ||
DaffCartItemInput, | ||
} from '../models/public_api'; | ||
|
||
export const daffCartItemInputToItemTransform = (input: DaffCartItemInput): DaffCartItem => ({ | ||
type: input.type, | ||
product_id: input.productId, | ||
qty: input.qty, | ||
|
||
item_id: null, | ||
id: null, | ||
parent_item_id: null, | ||
sku: null, | ||
name: null, | ||
price: null, | ||
row_total: null, | ||
in_stock: false, | ||
discounts: [], | ||
url: null, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './get-affected-item'; | ||
export * from './input-to-item-transform'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './errors/public_api'; | ||
export * from './models/public_api'; | ||
export * from './injection-tokens/public_api'; | ||
export * from './helpers/public_api'; | ||
|
||
export { DaffCartStorageService } from './storage/cart-storage.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.