@open-tender/utils 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels, NutritionalInfo } from '@open-tender/types';
1
+ import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, OrderCart, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels, NutritionalInfo } from '@open-tender/types';
2
2
  export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[];
3
3
  export declare const makeModifierNames: (item: CartItem) => string;
4
4
  export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
@@ -149,6 +149,13 @@ export declare const makeSimpleCart: (cart: Cart) => {
149
149
  made_for: string;
150
150
  notes: string;
151
151
  }[];
152
+ export declare const makeSimpleCartFromOrder: (cart: OrderCart) => {
153
+ id: number;
154
+ quantity: number;
155
+ groups: SimpleCartGroups;
156
+ made_for: string;
157
+ notes: string;
158
+ }[];
152
159
  export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut) => {
153
160
  newCart: (CartItem | CartItemOption | null)[];
154
161
  errors: {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.makeCartItemSignature = exports.makeItemSignature = exports.makeFavoritesLookup = exports.makeUniqueDisplayItems = exports.makeDisplayItems = exports.makeDisplayItem = exports.makeDisplayItemGroups = exports.makeItemImageUrl = exports.combineCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.calcCartCounts = exports.makeOrderItem = exports.checkSoldOut = exports.calcPrices = exports.calcNutritionalInfo = exports.calcNutrition = exports.makeUpsellItems = exports.makeModifierGroups = exports.hasGroupsBelowMin = exports.makeModifierNames = exports.getItemOptions = void 0;
3
+ exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCartFromOrder = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.makeCartItemSignature = exports.makeItemSignature = exports.makeFavoritesLookup = exports.makeUniqueDisplayItems = exports.makeDisplayItems = exports.makeDisplayItem = exports.makeDisplayItemGroups = exports.makeItemImageUrl = exports.combineCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.calcCartCounts = exports.makeOrderItem = exports.checkSoldOut = exports.calcPrices = exports.calcNutritionalInfo = exports.calcNutrition = exports.makeUpsellItems = exports.makeModifierGroups = exports.hasGroupsBelowMin = exports.makeModifierNames = exports.getItemOptions = void 0;
4
4
  const helpers_1 = require("./helpers");
5
5
  // TODO: refactor for nested mods
6
6
  const getItemOptions = (item) => {
@@ -603,6 +603,31 @@ const makeSimpleCart = (cart) => {
603
603
  return simpleCart;
604
604
  };
605
605
  exports.makeSimpleCart = makeSimpleCart;
606
+ const makeSimpleGroupsFromOrder = (groups) => {
607
+ return groups.map(g => {
608
+ const options = g.options
609
+ .filter(o => o.quantity !== 0)
610
+ .map(o => ({
611
+ id: o.id,
612
+ quantity: o.quantity,
613
+ groups: makeSimpleGroupsFromOrder(o.groups || [])
614
+ }));
615
+ return { id: g.id, options: options };
616
+ });
617
+ };
618
+ const makeSimpleCartFromOrder = (cart) => {
619
+ const simpleCart = cart.map(i => {
620
+ return {
621
+ id: i.id,
622
+ quantity: i.quantity,
623
+ groups: makeSimpleGroupsFromOrder(i.groups),
624
+ made_for: i.made_for || '',
625
+ notes: i.notes || ''
626
+ };
627
+ });
628
+ return simpleCart;
629
+ };
630
+ exports.makeSimpleCartFromOrder = makeSimpleCartFromOrder;
606
631
  /* cart validation */
607
632
  // TODO: refactor for nested modifiers
608
633
  // convert menu items to order items for validation but only include
@@ -1,4 +1,4 @@
1
- import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels, NutritionalInfo } from '@open-tender/types';
1
+ import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, OrderCart, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels, NutritionalInfo } from '@open-tender/types';
2
2
  export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[];
3
3
  export declare const makeModifierNames: (item: CartItem) => string;
4
4
  export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
@@ -149,6 +149,13 @@ export declare const makeSimpleCart: (cart: Cart) => {
149
149
  made_for: string;
150
150
  notes: string;
151
151
  }[];
152
+ export declare const makeSimpleCartFromOrder: (cart: OrderCart) => {
153
+ id: number;
154
+ quantity: number;
155
+ groups: SimpleCartGroups;
156
+ made_for: string;
157
+ notes: string;
158
+ }[];
152
159
  export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut) => {
153
160
  newCart: (CartItem | CartItemOption | null)[];
154
161
  errors: {
@@ -571,6 +571,30 @@ export const makeSimpleCart = (cart) => {
571
571
  });
572
572
  return simpleCart;
573
573
  };
574
+ const makeSimpleGroupsFromOrder = (groups) => {
575
+ return groups.map(g => {
576
+ const options = g.options
577
+ .filter(o => o.quantity !== 0)
578
+ .map(o => ({
579
+ id: o.id,
580
+ quantity: o.quantity,
581
+ groups: makeSimpleGroupsFromOrder(o.groups || [])
582
+ }));
583
+ return { id: g.id, options: options };
584
+ });
585
+ };
586
+ export const makeSimpleCartFromOrder = (cart) => {
587
+ const simpleCart = cart.map(i => {
588
+ return {
589
+ id: i.id,
590
+ quantity: i.quantity,
591
+ groups: makeSimpleGroupsFromOrder(i.groups),
592
+ made_for: i.made_for || '',
593
+ notes: i.notes || ''
594
+ };
595
+ });
596
+ return simpleCart;
597
+ };
574
598
  /* cart validation */
575
599
  // TODO: refactor for nested modifiers
576
600
  // convert menu items to order items for validation but only include
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",