@open-tender/utils 0.4.21 → 0.4.23

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.
@@ -6,7 +6,7 @@ export declare const useMenuItem: (builtItem: CartItem, auth: Auth | null, looku
6
6
  displayPrice: string;
7
7
  displayCals: number | null;
8
8
  totalPoints: number | null;
9
- totalAllergens: string[];
9
+ totalAllergens: string[] | undefined;
10
10
  auth: Auth | null;
11
11
  favoriteId: number | null;
12
12
  isIncomplete: boolean;
@@ -6,7 +6,7 @@ const useMenuItem = (builtItem, auth, lookup, cartId, displaySettings) => {
6
6
  const signature = (0, utils_1.makeItemSignature)(builtItem);
7
7
  const favoriteId = lookup && signature ? lookup[signature] : null;
8
8
  const { calories: showCals = false, tags: showTags = false, allergens: showAllergens = false, madeFor: showMadeFor = true, notes: showNotes = true } = displaySettings || {};
9
- const { description, quantity, price, totalPrice, cals, totalCals, totalPoints, tags, allergens, groups, ingredients } = builtItem;
9
+ const { description, quantity, price, totalPrice, cals, totalCals, totalPoints, tags, allergens, groups, ingredients, totalAllergens } = builtItem;
10
10
  const hasTags = showTags && Array.isArray(tags) && tags.length ? true : false;
11
11
  const hasAllergens = showAllergens && Array.isArray(allergens) && allergens.length ? true : false;
12
12
  const hasTagsAllergens = hasTags || hasAllergens ? true : false;
@@ -39,10 +39,6 @@ const useMenuItem = (builtItem, auth, lookup, cartId, displaySettings) => {
39
39
  const hasIngredients = ingredients && ingredients.length > 0;
40
40
  const hasCals = displayCals !== null;
41
41
  const hasInfo = hasCals || hasIngredients;
42
- const modifiersAllergens = currentOptions.reduce((t, o) => {
43
- return [...t, ...o.allergens];
44
- }, []);
45
- const totalAllergens = [...new Set(allergens.concat(modifiersAllergens))];
46
42
  return Object.assign(Object.assign({}, builtItem), { description,
47
43
  tags,
48
44
  allergens,
@@ -46,4 +46,5 @@ export declare const useModifier: (group: CartItemGroup, option: CartItemOption,
46
46
  totalCals: number | null;
47
47
  totalPoints: number | null;
48
48
  totalPrice: number | null;
49
+ totalAllergens?: string[] | undefined;
49
50
  };
@@ -41,4 +41,5 @@ export declare const useOrderItem: (orderItem: CartItem, favorite?: MenuItemFavo
41
41
  totalCals: number | null;
42
42
  totalPoints: number | null;
43
43
  totalPrice: number | null;
44
+ totalAllergens?: string[] | undefined;
44
45
  };
@@ -47,6 +47,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
47
47
  totalCals: number | null;
48
48
  totalPoints: number | null;
49
49
  totalPrice: number | null;
50
+ totalAllergens?: string[] | undefined;
50
51
  }[];
51
52
  cartCounts: Record<string, number>;
52
53
  };
@@ -133,6 +134,7 @@ export declare const combineCarts: (cart: Cart, guestCart: Cart, cartOwner: Cart
133
134
  totalCals: number | null;
134
135
  totalPoints: number | null;
135
136
  totalPrice: number | null;
137
+ totalAllergens?: string[] | undefined;
136
138
  }[];
137
139
  export declare const makeItemImageUrl: (images: Images) => any;
138
140
  export declare const makeDisplayItemGroups: (optionGroups: OrderItemGroups) => {
@@ -178,7 +178,15 @@ const calcPrices = (item) => {
178
178
  const totalCals = item.cals || item.cals === 0
179
179
  ? item.quantity * (item.cals + optionsCals)
180
180
  : null;
181
- return Object.assign(Object.assign({}, item), { groups, totalPrice, totalPoints, totalCals });
181
+ const nonSizeGroups = groups ? groups.filter(i => !i.isSize) : null;
182
+ const currentOptions = nonSizeGroups
183
+ ? (0, exports.getItemOptions)(Object.assign(Object.assign({}, item), { groups: nonSizeGroups }))
184
+ : [];
185
+ const modifiersAllergens = currentOptions.reduce((t, o) => {
186
+ return [...t, ...o.allergens];
187
+ }, []);
188
+ const totalAllergens = [...new Set(item.allergens.concat(modifiersAllergens))];
189
+ return Object.assign(Object.assign({}, item), { groups, totalPrice, totalPoints, totalCals, totalAllergens });
182
190
  };
183
191
  exports.calcPrices = calcPrices;
184
192
  const checkSoldOut = (id, suspendUntil, soldOut = []) => {
@@ -6,7 +6,7 @@ export declare const useMenuItem: (builtItem: CartItem, auth: Auth | null, looku
6
6
  displayPrice: string;
7
7
  displayCals: number | null;
8
8
  totalPoints: number | null;
9
- totalAllergens: string[];
9
+ totalAllergens: string[] | undefined;
10
10
  auth: Auth | null;
11
11
  favoriteId: number | null;
12
12
  isIncomplete: boolean;
@@ -3,7 +3,7 @@ export const useMenuItem = (builtItem, auth, lookup, cartId, displaySettings) =>
3
3
  const signature = makeItemSignature(builtItem);
4
4
  const favoriteId = lookup && signature ? lookup[signature] : null;
5
5
  const { calories: showCals = false, tags: showTags = false, allergens: showAllergens = false, madeFor: showMadeFor = true, notes: showNotes = true } = displaySettings || {};
6
- const { description, quantity, price, totalPrice, cals, totalCals, totalPoints, tags, allergens, groups, ingredients } = builtItem;
6
+ const { description, quantity, price, totalPrice, cals, totalCals, totalPoints, tags, allergens, groups, ingredients, totalAllergens } = builtItem;
7
7
  const hasTags = showTags && Array.isArray(tags) && tags.length ? true : false;
8
8
  const hasAllergens = showAllergens && Array.isArray(allergens) && allergens.length ? true : false;
9
9
  const hasTagsAllergens = hasTags || hasAllergens ? true : false;
@@ -36,10 +36,6 @@ export const useMenuItem = (builtItem, auth, lookup, cartId, displaySettings) =>
36
36
  const hasIngredients = ingredients && ingredients.length > 0;
37
37
  const hasCals = displayCals !== null;
38
38
  const hasInfo = hasCals || hasIngredients;
39
- const modifiersAllergens = currentOptions.reduce((t, o) => {
40
- return [...t, ...o.allergens];
41
- }, []);
42
- const totalAllergens = [...new Set(allergens.concat(modifiersAllergens))];
43
39
  return Object.assign(Object.assign({}, builtItem), { description,
44
40
  tags,
45
41
  allergens,
@@ -46,4 +46,5 @@ export declare const useModifier: (group: CartItemGroup, option: CartItemOption,
46
46
  totalCals: number | null;
47
47
  totalPoints: number | null;
48
48
  totalPrice: number | null;
49
+ totalAllergens?: string[] | undefined;
49
50
  };
@@ -41,4 +41,5 @@ export declare const useOrderItem: (orderItem: CartItem, favorite?: MenuItemFavo
41
41
  totalCals: number | null;
42
42
  totalPoints: number | null;
43
43
  totalPrice: number | null;
44
+ totalAllergens?: string[] | undefined;
44
45
  };
@@ -47,6 +47,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
47
47
  totalCals: number | null;
48
48
  totalPoints: number | null;
49
49
  totalPrice: number | null;
50
+ totalAllergens?: string[] | undefined;
50
51
  }[];
51
52
  cartCounts: Record<string, number>;
52
53
  };
@@ -133,6 +134,7 @@ export declare const combineCarts: (cart: Cart, guestCart: Cart, cartOwner: Cart
133
134
  totalCals: number | null;
134
135
  totalPoints: number | null;
135
136
  totalPrice: number | null;
137
+ totalAllergens?: string[] | undefined;
136
138
  }[];
137
139
  export declare const makeItemImageUrl: (images: Images) => any;
138
140
  export declare const makeDisplayItemGroups: (optionGroups: OrderItemGroups) => {
@@ -165,7 +165,15 @@ export const calcPrices = (item) => {
165
165
  const totalCals = item.cals || item.cals === 0
166
166
  ? item.quantity * (item.cals + optionsCals)
167
167
  : null;
168
- return Object.assign(Object.assign({}, item), { groups, totalPrice, totalPoints, totalCals });
168
+ const nonSizeGroups = groups ? groups.filter(i => !i.isSize) : null;
169
+ const currentOptions = nonSizeGroups
170
+ ? getItemOptions(Object.assign(Object.assign({}, item), { groups: nonSizeGroups }))
171
+ : [];
172
+ const modifiersAllergens = currentOptions.reduce((t, o) => {
173
+ return [...t, ...o.allergens];
174
+ }, []);
175
+ const totalAllergens = [...new Set(item.allergens.concat(modifiersAllergens))];
176
+ return Object.assign(Object.assign({}, item), { groups, totalPrice, totalPoints, totalCals, totalAllergens });
169
177
  };
170
178
  export const checkSoldOut = (id, suspendUntil, soldOut = []) => {
171
179
  if (soldOut.includes(id))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.4.21",
3
+ "version": "0.4.23",
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",