@open-tender/utils 0.5.48 → 0.5.50

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.
@@ -726,18 +726,6 @@ const makeGroupsLookup = (item) => {
726
726
  return grpObj;
727
727
  }, {});
728
728
  };
729
- const makeGroupsLookupByExtId = (item) => {
730
- return item.groups.reduce((grpObj, i) => {
731
- const options = i.options.reduce((optObj, o) => {
732
- if (o.pos_ext_id) {
733
- optObj[o.pos_ext_id] = o;
734
- }
735
- return optObj;
736
- }, {});
737
- grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
738
- return grpObj;
739
- }, {});
740
- };
741
729
  // TODO: refactor for nested modifiers
742
730
  const validateCart = (cart, categories, soldOut, requestedAt) => {
743
731
  const itemIds = cart.map(item => item.id);
@@ -758,7 +746,6 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
758
746
  const missingOptions = [];
759
747
  const invalidOptions = [];
760
748
  const newGroups = makeGroupsLookup(newItem);
761
- const newGroupsByExtId = makeGroupsLookupByExtId(newItem);
762
749
  // check if any required groups for the new item are missing from the old item
763
750
  const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
764
751
  const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
@@ -770,7 +757,7 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
770
757
  .map((i) => (Object.assign(Object.assign({}, i), { options: Object.values(i.options) })));
771
758
  const updatedGroups = (_b = oldItem.groups) === null || _b === void 0 ? void 0 : _b.map(group => {
772
759
  const optionCount = group.options.reduce((t, i) => (t += i.quantity), 0);
773
- const newGroup = newGroups[group.id] || newGroupsByExtId[group.id];
760
+ const newGroup = newGroups[group.id];
774
761
  // check if option group is still part of the item
775
762
  if (!newGroup) {
776
763
  if (optionCount > 0) {
@@ -783,8 +770,13 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
783
770
  }
784
771
  else {
785
772
  const updatedOptions = group.options.map(option => {
786
- const newOption = newGroup.options[option.id] ||
787
- (option.pos_ext_id && newGroup.options[option.pos_ext_id]);
773
+ let newOption = newGroup.options[option.id];
774
+ if (!newOption) {
775
+ const allOptions = Object.values(newGroup.options);
776
+ const matchingOption = allOptions.find(o => o.pos_ext_id === option.pos_ext_id);
777
+ if (matchingOption)
778
+ newOption = matchingOption;
779
+ }
788
780
  // check to see if any OLD options aren't avaiilable on the current menu
789
781
  // or if any of the options are currently sold out
790
782
  if (!newOption ||
@@ -690,18 +690,6 @@ const makeGroupsLookup = (item) => {
690
690
  return grpObj;
691
691
  }, {});
692
692
  };
693
- const makeGroupsLookupByExtId = (item) => {
694
- return item.groups.reduce((grpObj, i) => {
695
- const options = i.options.reduce((optObj, o) => {
696
- if (o.pos_ext_id) {
697
- optObj[o.pos_ext_id] = o;
698
- }
699
- return optObj;
700
- }, {});
701
- grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
702
- return grpObj;
703
- }, {});
704
- };
705
693
  // TODO: refactor for nested modifiers
706
694
  export const validateCart = (cart, categories, soldOut, requestedAt) => {
707
695
  const itemIds = cart.map(item => item.id);
@@ -722,7 +710,6 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
722
710
  const missingOptions = [];
723
711
  const invalidOptions = [];
724
712
  const newGroups = makeGroupsLookup(newItem);
725
- const newGroupsByExtId = makeGroupsLookupByExtId(newItem);
726
713
  // check if any required groups for the new item are missing from the old item
727
714
  const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
728
715
  const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
@@ -734,7 +721,7 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
734
721
  .map((i) => (Object.assign(Object.assign({}, i), { options: Object.values(i.options) })));
735
722
  const updatedGroups = (_b = oldItem.groups) === null || _b === void 0 ? void 0 : _b.map(group => {
736
723
  const optionCount = group.options.reduce((t, i) => (t += i.quantity), 0);
737
- const newGroup = newGroups[group.id] || newGroupsByExtId[group.id];
724
+ const newGroup = newGroups[group.id];
738
725
  // check if option group is still part of the item
739
726
  if (!newGroup) {
740
727
  if (optionCount > 0) {
@@ -747,8 +734,13 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
747
734
  }
748
735
  else {
749
736
  const updatedOptions = group.options.map(option => {
750
- const newOption = newGroup.options[option.id] ||
751
- (option.pos_ext_id && newGroup.options[option.pos_ext_id]);
737
+ let newOption = newGroup.options[option.id];
738
+ if (!newOption) {
739
+ const allOptions = Object.values(newGroup.options);
740
+ const matchingOption = allOptions.find(o => o.pos_ext_id === option.pos_ext_id);
741
+ if (matchingOption)
742
+ newOption = matchingOption;
743
+ }
752
744
  // check to see if any OLD options aren't avaiilable on the current menu
753
745
  // or if any of the options are currently sold out
754
746
  if (!newOption ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.5.48",
3
+ "version": "0.5.50",
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",