@open-tender/utils 0.5.46 → 0.5.47

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,6 +726,18 @@ 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
+ };
729
741
  // TODO: refactor for nested modifiers
730
742
  const validateCart = (cart, categories, soldOut, requestedAt) => {
731
743
  const itemIds = cart.map(item => item.id);
@@ -746,6 +758,7 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
746
758
  const missingOptions = [];
747
759
  const invalidOptions = [];
748
760
  const newGroups = makeGroupsLookup(newItem);
761
+ const newGroupsByExtId = makeGroupsLookupByExtId(newItem);
749
762
  // check if any required groups for the new item are missing from the old item
750
763
  const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
751
764
  const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
@@ -770,7 +783,8 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
770
783
  }
771
784
  else {
772
785
  const updatedOptions = group.options.map(option => {
773
- const newOption = newGroup.options[option.id];
786
+ const newOption = newGroup.options[option.id] ||
787
+ (option.pos_ext_id && newGroupsByExtId[option.pos_ext_id]);
774
788
  // check to see if any OLD options aren't avaiilable on the current menu
775
789
  // or if any of the options are currently sold out
776
790
  if (!newOption ||
@@ -690,6 +690,18 @@ 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
+ };
693
705
  // TODO: refactor for nested modifiers
694
706
  export const validateCart = (cart, categories, soldOut, requestedAt) => {
695
707
  const itemIds = cart.map(item => item.id);
@@ -710,6 +722,7 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
710
722
  const missingOptions = [];
711
723
  const invalidOptions = [];
712
724
  const newGroups = makeGroupsLookup(newItem);
725
+ const newGroupsByExtId = makeGroupsLookupByExtId(newItem);
713
726
  // check if any required groups for the new item are missing from the old item
714
727
  const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
715
728
  const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
@@ -734,7 +747,8 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
734
747
  }
735
748
  else {
736
749
  const updatedOptions = group.options.map(option => {
737
- const newOption = newGroup.options[option.id];
750
+ const newOption = newGroup.options[option.id] ||
751
+ (option.pos_ext_id && newGroupsByExtId[option.pos_ext_id]);
738
752
  // check to see if any OLD options aren't avaiilable on the current menu
739
753
  // or if any of the options are currently sold out
740
754
  if (!newOption ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.5.46",
3
+ "version": "0.5.47",
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",