@open-tender/utils 0.1.7 → 0.1.9

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;
@@ -142,7 +142,28 @@ export declare const decrementItem: (cart: Cart, index: number) => {
142
142
  cart: Cart;
143
143
  cartCounts: Record<string, number>;
144
144
  };
145
- export declare const makeSimpleCart: (cart: Cart) => {
145
+ export declare const makeSimpleCart: <C extends {
146
+ id: number;
147
+ quantity: number;
148
+ groups: T[];
149
+ madeFor?: string | null | undefined;
150
+ made_for?: string | null | undefined;
151
+ notes?: string | null | undefined;
152
+ }[], T extends {
153
+ id: number;
154
+ options: K[];
155
+ }, K extends {
156
+ id: number;
157
+ quantity: number;
158
+ groups: T[];
159
+ }>(cart: C) => {
160
+ id: number;
161
+ quantity: number;
162
+ groups: SimpleCartGroups;
163
+ made_for: string;
164
+ notes: string;
165
+ }[];
166
+ export declare const makeSimpleCartFromOrder: (cart: OrderCart) => {
146
167
  id: number;
147
168
  quantity: number;
148
169
  groups: SimpleCartGroups;
@@ -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) => {
@@ -596,13 +596,62 @@ const makeSimpleCart = (cart) => {
596
596
  id: i.id,
597
597
  quantity: i.quantity,
598
598
  groups: makeSimpleGroups(i.groups),
599
- made_for: i.madeFor || '',
599
+ made_for: i.madeFor || i.made_for || '',
600
600
  notes: i.notes || ''
601
601
  };
602
602
  });
603
603
  return simpleCart;
604
604
  };
605
605
  exports.makeSimpleCart = makeSimpleCart;
606
+ // const makeSimpleGroups = (groups: CartItemGroups): SimpleCartGroups => {
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: makeSimpleGroups(o.groups || [])
614
+ // }))
615
+ // return { id: g.id, options: options }
616
+ // })
617
+ // }
618
+ // export const makeSimpleCart = (cart: Cart) => {
619
+ // const simpleCart = cart.map(i => {
620
+ // return {
621
+ // id: i.id,
622
+ // quantity: i.quantity,
623
+ // groups: makeSimpleGroups(i.groups),
624
+ // made_for: i.madeFor || '',
625
+ // notes: i.notes || ''
626
+ // }
627
+ // })
628
+ // return simpleCart
629
+ // }
630
+ const makeSimpleGroupsFromOrder = (groups) => {
631
+ return groups.map(g => {
632
+ const options = g.options
633
+ .filter(o => o.quantity !== 0)
634
+ .map(o => ({
635
+ id: o.id,
636
+ quantity: o.quantity,
637
+ groups: makeSimpleGroupsFromOrder(o.groups || [])
638
+ }));
639
+ return { id: g.id, options: options };
640
+ });
641
+ };
642
+ const makeSimpleCartFromOrder = (cart) => {
643
+ const simpleCart = cart.map(i => {
644
+ return {
645
+ id: i.id,
646
+ quantity: i.quantity,
647
+ groups: makeSimpleGroupsFromOrder(i.groups),
648
+ made_for: i.made_for || '',
649
+ notes: i.notes || ''
650
+ };
651
+ });
652
+ return simpleCart;
653
+ };
654
+ exports.makeSimpleCartFromOrder = makeSimpleCartFromOrder;
606
655
  /* cart validation */
607
656
  // TODO: refactor for nested modifiers
608
657
  // 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;
@@ -142,7 +142,28 @@ export declare const decrementItem: (cart: Cart, index: number) => {
142
142
  cart: Cart;
143
143
  cartCounts: Record<string, number>;
144
144
  };
145
- export declare const makeSimpleCart: (cart: Cart) => {
145
+ export declare const makeSimpleCart: <C extends {
146
+ id: number;
147
+ quantity: number;
148
+ groups: T[];
149
+ madeFor?: string | null | undefined;
150
+ made_for?: string | null | undefined;
151
+ notes?: string | null | undefined;
152
+ }[], T extends {
153
+ id: number;
154
+ options: K[];
155
+ }, K extends {
156
+ id: number;
157
+ quantity: number;
158
+ groups: T[];
159
+ }>(cart: C) => {
160
+ id: number;
161
+ quantity: number;
162
+ groups: SimpleCartGroups;
163
+ made_for: string;
164
+ notes: string;
165
+ }[];
166
+ export declare const makeSimpleCartFromOrder: (cart: OrderCart) => {
146
167
  id: number;
147
168
  quantity: number;
148
169
  groups: SimpleCartGroups;
@@ -565,7 +565,55 @@ export const makeSimpleCart = (cart) => {
565
565
  id: i.id,
566
566
  quantity: i.quantity,
567
567
  groups: makeSimpleGroups(i.groups),
568
- made_for: i.madeFor || '',
568
+ made_for: i.madeFor || i.made_for || '',
569
+ notes: i.notes || ''
570
+ };
571
+ });
572
+ return simpleCart;
573
+ };
574
+ // const makeSimpleGroups = (groups: CartItemGroups): SimpleCartGroups => {
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: makeSimpleGroups(o.groups || [])
582
+ // }))
583
+ // return { id: g.id, options: options }
584
+ // })
585
+ // }
586
+ // export const makeSimpleCart = (cart: Cart) => {
587
+ // const simpleCart = cart.map(i => {
588
+ // return {
589
+ // id: i.id,
590
+ // quantity: i.quantity,
591
+ // groups: makeSimpleGroups(i.groups),
592
+ // made_for: i.madeFor || '',
593
+ // notes: i.notes || ''
594
+ // }
595
+ // })
596
+ // return simpleCart
597
+ // }
598
+ const makeSimpleGroupsFromOrder = (groups) => {
599
+ return groups.map(g => {
600
+ const options = g.options
601
+ .filter(o => o.quantity !== 0)
602
+ .map(o => ({
603
+ id: o.id,
604
+ quantity: o.quantity,
605
+ groups: makeSimpleGroupsFromOrder(o.groups || [])
606
+ }));
607
+ return { id: g.id, options: options };
608
+ });
609
+ };
610
+ export const makeSimpleCartFromOrder = (cart) => {
611
+ const simpleCart = cart.map(i => {
612
+ return {
613
+ id: i.id,
614
+ quantity: i.quantity,
615
+ groups: makeSimpleGroupsFromOrder(i.groups),
616
+ made_for: i.made_for || '',
569
617
  notes: i.notes || ''
570
618
  };
571
619
  });
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.9",
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",