@open-tender/utils 0.5.49 → 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);
@@ -771,7 +758,6 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
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
760
  const newGroup = newGroups[group.id];
774
- const newGroupByExtId = newGroupsByExtId[group.id];
775
761
  // check if option group is still part of the item
776
762
  if (!newGroup) {
777
763
  if (optionCount > 0) {
@@ -784,8 +770,13 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
784
770
  }
785
771
  else {
786
772
  const updatedOptions = group.options.map(option => {
787
- const newOption = newGroup.options[option.id] ||
788
- (option.pos_ext_id && newGroupByExtId.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
+ }
789
780
  // check to see if any OLD options aren't avaiilable on the current menu
790
781
  // or if any of the options are currently sold out
791
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);
@@ -735,7 +722,6 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
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
724
  const newGroup = newGroups[group.id];
738
- const newGroupByExtId = newGroupsByExtId[group.id];
739
725
  // check if option group is still part of the item
740
726
  if (!newGroup) {
741
727
  if (optionCount > 0) {
@@ -748,8 +734,13 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
748
734
  }
749
735
  else {
750
736
  const updatedOptions = group.options.map(option => {
751
- const newOption = newGroup.options[option.id] ||
752
- (option.pos_ext_id && newGroupByExtId.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
+ }
753
744
  // check to see if any OLD options aren't avaiilable on the current menu
754
745
  // or if any of the options are currently sold out
755
746
  if (!newOption ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.5.49",
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",