@darkpos/pricing 1.0.5 → 1.0.8

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.
Files changed (242) hide show
  1. package/.eslintrc +8 -10
  2. package/__TEST__/item.test.js +137 -99
  3. package/__TEST__/modifier/calculate.test.js +73 -0
  4. package/__TEST__/modifier/getAvailablePromotionsOrSubscriptions.test.js +81 -0
  5. package/__TEST__/modifier/getMatchTagsModifiers.test.js +109 -0
  6. package/__TEST__/modifier/getModifierIndex.test.js +40 -0
  7. package/__TEST__/modifier/getRecommendedModifiers.test.js +17 -0
  8. package/__TEST__/modifier/hasAllTags.test.js +25 -0
  9. package/__TEST__/modifier/hasAttribute.test.js +47 -0
  10. package/__TEST__/modifier/hasMatchTags.test.js +56 -0
  11. package/__TEST__/modifier/hasNoTags.test.js +21 -0
  12. package/__TEST__/modifier/mocks/toggleModifier_no1.json +13440 -0
  13. package/__TEST__/modifier/mocks/toggleModifier_no2.json +13438 -0
  14. package/__TEST__/modifier/mocks/toggleModifier_no3.json +13598 -0
  15. package/__TEST__/modifier/sort.test.js +41 -0
  16. package/__TEST__/order.test.js +50 -37
  17. package/index.js +1 -25
  18. package/lib/constants/Modifier/Attributes.js +9 -0
  19. package/lib/constants/Modifier/Compute.js +15 -0
  20. package/lib/constants/Modifier/Types.js +7 -0
  21. package/lib/constants/Modifier/index.js +9 -0
  22. package/lib/constants/Status.js +39 -0
  23. package/lib/constants/index.js +7 -0
  24. package/lib/constants/status.js +39 -0
  25. package/lib/index.js +38 -0
  26. package/lib/item/addIndirectModifier.js +34 -17
  27. package/lib/item/calculate.js +41 -19
  28. package/lib/item/create.js +35 -0
  29. package/lib/item/filterByDirectModifiers.js +5 -6
  30. package/lib/item/findOriginalItem.js +8 -0
  31. package/lib/item/getBalanceToPay.js +12 -0
  32. package/lib/item/getDepartmentModifiers.js +5 -0
  33. package/lib/item/getDiscountModifiers.js +7 -0
  34. package/lib/item/getItemModifiers.js +16 -0
  35. package/lib/item/getItemModifiersDescription.js +22 -0
  36. package/lib/item/getItemPrice.js +57 -0
  37. package/lib/item/getItemsTotalPaid.js +9 -0
  38. package/lib/item/getItemsTotalPieces.js +7 -0
  39. package/lib/item/getNotIncludedModifiers.js +11 -0
  40. package/lib/item/getParentItem.js +5 -0
  41. package/lib/item/getPendingIndex.js +5 -0
  42. package/lib/item/getTotal.js +8 -0
  43. package/lib/item/getTotalPieces.js +7 -0
  44. package/lib/item/getTotals.js +25 -0
  45. package/lib/item/hasCreateSubscription.js +7 -0
  46. package/lib/item/hasModifier.js +15 -0
  47. package/lib/item/hasModifierWithValue.js +11 -0
  48. package/lib/item/hasModifiers.js +9 -0
  49. package/lib/item/hasSubscription.js +5 -0
  50. package/lib/item/index.js +80 -10
  51. package/lib/item/isParentIncluded.js +4 -0
  52. package/lib/item/isRelatedItem.js +4 -0
  53. package/lib/item/isSelected.js +13 -0
  54. package/lib/item/openRecommendationDialog.js +4 -0
  55. package/lib/item/removeModifier.js +84 -0
  56. package/lib/item/removeModifierById.js +8 -0
  57. package/lib/item/removeModifiers.js +14 -0
  58. package/lib/modifier/addFile.js +19 -0
  59. package/lib/modifier/addImage.js +18 -0
  60. package/lib/modifier/calculate.js +43 -0
  61. package/lib/modifier/contains.js +5 -0
  62. package/lib/modifier/convertMenuModifiers.js +5 -0
  63. package/lib/modifier/create.js +44 -0
  64. package/lib/modifier/createAmountOverrideModifier.js +20 -0
  65. package/lib/modifier/createCreditModifier.js +32 -0
  66. package/lib/modifier/createDiscountModifier.js +25 -0
  67. package/lib/modifier/createGroupValuesModifier.js +29 -0
  68. package/lib/modifier/createIndirectModifier.js +42 -0
  69. package/lib/modifier/createSubscriptionModifier.js +19 -0
  70. package/lib/modifier/displayAsCard.js +9 -0
  71. package/lib/modifier/displayAsChips.js +9 -0
  72. package/lib/modifier/displayAsList.js +9 -0
  73. package/lib/modifier/duplicate.js +12 -0
  74. package/lib/modifier/enableAutoPopup.js +9 -0
  75. package/lib/modifier/filterByRequiredModifiers.js +4 -0
  76. package/lib/modifier/findById.js +7 -0
  77. package/lib/modifier/findByPaymentMethod.js +10 -0
  78. package/lib/modifier/findByPaymentType.js +10 -0
  79. package/lib/modifier/getAvailablePromotions.js +5 -0
  80. package/lib/modifier/getAvailablePromotionsOrSubscriptions.js +15 -0
  81. package/lib/modifier/getAvailableSubscriptions.js +5 -0
  82. package/lib/modifier/getByAttribute.js +6 -0
  83. package/lib/modifier/getCreditModifier.js +6 -0
  84. package/lib/modifier/getDefaultModifiers.js +4 -0
  85. package/lib/modifier/getDepartmentMaxItems.js +10 -0
  86. package/lib/modifier/getDepartmentModifiers.js +11 -0
  87. package/lib/modifier/getDescription.js +6 -0
  88. package/lib/modifier/getDescriptions.js +9 -0
  89. package/lib/modifier/getDirectModifiers.js +5 -0
  90. package/lib/modifier/getDiscountModifiers.js +7 -0
  91. package/lib/modifier/getEntityModifiers.js +11 -0
  92. package/lib/modifier/getEntityPromotions.js +11 -0
  93. package/lib/modifier/getExtendedTags.js +14 -0
  94. package/lib/modifier/getFiles.js +5 -0
  95. package/lib/modifier/getGroupModifiers.js +9 -0
  96. package/lib/modifier/getGroupOfItemsModifiers.js +4 -0
  97. package/lib/modifier/getGroupRelatedModifiers.js +26 -0
  98. package/lib/modifier/getImages.js +5 -0
  99. package/lib/modifier/getInheritedModifiers.js +30 -0
  100. package/lib/modifier/getItemModifiers.js +39 -0
  101. package/lib/modifier/getLaundryModifiers.js +9 -0
  102. package/lib/modifier/getMatchTagsModifiers.js +9 -0
  103. package/lib/modifier/getModifierIndex.js +14 -0
  104. package/lib/modifier/getPreferences.js +24 -0
  105. package/lib/modifier/getPromotionModifiers.js +5 -0
  106. package/lib/modifier/getPromptMessage.js +6 -0
  107. package/lib/modifier/getProperty.js +11 -0
  108. package/lib/modifier/getRecommendedModifiers.js +7 -0
  109. package/lib/modifier/getRelatedModifiers.js +10 -0
  110. package/lib/modifier/getRequiredModifiers.js +4 -0
  111. package/lib/modifier/getSelectedValues.js +7 -0
  112. package/lib/modifier/getService.js +5 -0
  113. package/lib/modifier/getSplittedModifiers.js +30 -0
  114. package/lib/modifier/getStarchModifier.js +9 -0
  115. package/lib/modifier/getSubscriptionItem.js +12 -0
  116. package/lib/modifier/getSubscriptionModifiers.js +5 -0
  117. package/lib/modifier/getSuggestion.js +9 -0
  118. package/lib/modifier/getUnhiddenModifiers.js +9 -0
  119. package/lib/modifier/getUsingCount.js +11 -0
  120. package/lib/modifier/hasAddModifiers.js +5 -0
  121. package/lib/modifier/hasAllTag.js +12 -0
  122. package/lib/modifier/hasAttribute.js +8 -0
  123. package/lib/modifier/hasAttributes.js +19 -0
  124. package/lib/modifier/hasCreateSubscription.js +10 -0
  125. package/lib/modifier/hasDisplayPrompt.js +9 -0
  126. package/lib/modifier/hasMatchTags.js +27 -0
  127. package/lib/modifier/hasModifier.js +12 -0
  128. package/lib/modifier/hasNoTags.js +9 -0
  129. package/lib/modifier/hasRelatedItems.js +8 -0
  130. package/lib/modifier/includePiecesInQuantity.js +10 -0
  131. package/lib/modifier/includesInGroup.js +9 -0
  132. package/lib/modifier/index.js +242 -0
  133. package/lib/modifier/isAmountOverride.js +7 -0
  134. package/lib/modifier/isAvailablePromotion.js +23 -0
  135. package/lib/modifier/isAvailableSubscription.js +28 -0
  136. package/lib/modifier/isCompact.js +12 -0
  137. package/lib/modifier/isCredit.js +6 -0
  138. package/lib/modifier/isCustomerTagsExtend.js +9 -0
  139. package/lib/modifier/isDefault.js +4 -0
  140. package/lib/modifier/isDepartment.js +6 -0
  141. package/lib/modifier/isDirect.js +6 -0
  142. package/lib/modifier/isDiscount.js +6 -0
  143. package/lib/modifier/isEditable.js +10 -0
  144. package/lib/modifier/isGratuity.js +6 -0
  145. package/lib/modifier/isGroupOfItems.js +12 -0
  146. package/lib/modifier/isGroupOfModifiers.js +12 -0
  147. package/lib/modifier/isGroupOfValues.js +13 -0
  148. package/lib/modifier/isHidden.js +4 -0
  149. package/lib/modifier/isIncluded.js +4 -0
  150. package/lib/modifier/isManual.js +9 -0
  151. package/lib/modifier/isMultiplier.js +11 -0
  152. package/lib/modifier/isOverride.js +6 -0
  153. package/lib/modifier/isPaymentMethods.js +8 -0
  154. package/lib/modifier/isPaymentTypes.js +8 -0
  155. package/lib/modifier/isPreferences.js +8 -0
  156. package/lib/modifier/isPriceOverride.js +7 -0
  157. package/lib/modifier/isPromotion.js +6 -0
  158. package/lib/modifier/isQuantityOverride.js +7 -0
  159. package/lib/modifier/isRemoveModifier.js +4 -0
  160. package/lib/modifier/isRequired.js +4 -0
  161. package/lib/modifier/isRequiredAndOverride.js +4 -0
  162. package/lib/modifier/isService.js +9 -0
  163. package/lib/modifier/isSingleValue.js +9 -0
  164. package/lib/modifier/isSubscription.js +6 -0
  165. package/lib/modifier/isTrackUsageSubscription.js +5 -0
  166. package/lib/modifier/isValueSelected.js +7 -0
  167. package/lib/modifier/purifyModifiers.js +15 -0
  168. package/lib/modifier/sort.js +35 -0
  169. package/lib/order/addCreditModifier.js +27 -0
  170. package/lib/order/addDiscountModifier.js +9 -0
  171. package/lib/order/addItem.js +292 -0
  172. package/lib/order/addItemModifier.js +214 -0
  173. package/lib/order/addModifier.js +9 -0
  174. package/lib/order/addModifierToAllItems.js +16 -0
  175. package/lib/order/addNote.js +25 -0
  176. package/lib/order/addTable.js +11 -0
  177. package/lib/order/calculate.js +51 -16
  178. package/lib/order/calculateDue.js +15 -0
  179. package/lib/order/calculateOrdersDue.js +26 -0
  180. package/lib/order/canSplit.js +4 -0
  181. package/lib/order/changeEndDate.js +15 -0
  182. package/lib/order/changeLocation.js +20 -0
  183. package/lib/order/changeStartDate.js +14 -0
  184. package/lib/order/combineSubOrders.js +14 -0
  185. package/lib/order/containsSerial.js +5 -0
  186. package/lib/order/create.js +67 -0
  187. package/lib/order/createParent.js +9 -0
  188. package/lib/order/duplicateItem.js +16 -0
  189. package/lib/order/findItemIndex.js +6 -0
  190. package/lib/order/getAppliedCredit.js +5 -0
  191. package/lib/order/getBalance.js +9 -0
  192. package/lib/order/getCustomer.js +4 -0
  193. package/lib/order/getCustomerStoreCredit.js +14 -0
  194. package/lib/order/getCustomerSubscriptions.js +8 -0
  195. package/lib/order/getCustomerSubscriptionsByItem.js +14 -0
  196. package/lib/order/getDepartmentModifiers.js +9 -0
  197. package/lib/order/getEndDate.js +4 -0
  198. package/lib/order/getItemByItemId.js +6 -0
  199. package/lib/order/getItemIndex.js +9 -0
  200. package/lib/order/getItemsToPay.js +17 -0
  201. package/lib/order/getMenuItemsByCustomer.js +19 -0
  202. package/lib/order/getNumberOfItems.js +10 -0
  203. package/lib/order/getOrdersPieces.js +10 -0
  204. package/lib/order/getPendingItemIndex.js +5 -0
  205. package/lib/order/getRelatedItems.js +11 -0
  206. package/lib/order/getSameItems.js +19 -0
  207. package/lib/order/getScheduleByCustomer.js +20 -0
  208. package/lib/order/getScreenCustomerNotes.js +12 -0
  209. package/lib/order/getSelectedItem.js +6 -0
  210. package/lib/order/getStartDate.js +4 -0
  211. package/lib/order/getTip.js +10 -0
  212. package/lib/order/getTotalPieces.js +17 -0
  213. package/lib/order/getTotals.js +28 -0
  214. package/lib/order/hasAggregate.js +20 -0
  215. package/lib/order/hasItem.js +7 -0
  216. package/lib/order/hasRemainingSubscription.js +67 -0
  217. package/lib/order/hold.js +12 -0
  218. package/lib/order/index.js +163 -5
  219. package/lib/order/isDetailed.js +4 -0
  220. package/lib/order/isHold.js +4 -0
  221. package/lib/order/isNew.js +4 -0
  222. package/lib/order/isOpen.js +4 -0
  223. package/lib/order/isParent.js +7 -0
  224. package/lib/order/merge.js +96 -0
  225. package/lib/order/open.js +11 -0
  226. package/lib/order/pickEndDate.js +70 -0
  227. package/lib/order/removeApplyModifier.js +24 -0
  228. package/lib/order/removeDiscountModifier.js +16 -0
  229. package/lib/order/removeItem.js +55 -0
  230. package/lib/order/removeItemByIndex.js +5 -0
  231. package/lib/order/removeItemModifier.js +69 -0
  232. package/lib/order/removeModifier.js +21 -0
  233. package/lib/order/removeModifierByAttribute.js +23 -0
  234. package/lib/order/removeModifiersWithPaymentMethods.js +29 -0
  235. package/lib/order/removeModifiersWithPaymentTypes.js +27 -0
  236. package/lib/order/setCustomer.js +50 -0
  237. package/lib/order/splitByDepartments.js +151 -0
  238. package/lib/order/toggleModifier.js +9 -0
  239. package/lib/order/updateItem.js +8 -0
  240. package/lib/order/updateItemQuantity.js +35 -0
  241. package/lib/order/void.js +11 -0
  242. package/package.json +15 -18
@@ -0,0 +1,32 @@
1
+ module.exports = ({ _, actions, utils }) => {
2
+ const { helpers } = utils;
3
+ //
4
+ return function createCreditModifier(modifier = {}) {
5
+ const { customerStoredCredit, ...rest } = _.cloneDeep(modifier);
6
+ if (!customerStoredCredit) return null;
7
+ let creditModifier;
8
+ if (!_.isEmpty(rest)) {
9
+ creditModifier = rest;
10
+ }
11
+ // create one
12
+ else {
13
+ creditModifier = actions.create({
14
+ _id: helpers.getObjectID(),
15
+ type: 'credit',
16
+ name: 'Customer stored credit',
17
+ direct: true,
18
+ });
19
+ }
20
+
21
+ creditModifier.compute = {
22
+ amount: 100,
23
+ type: 'percentage',
24
+ action: 'subtract',
25
+ };
26
+ creditModifier.properties = {
27
+ maxAmount: customerStoredCredit,
28
+ sort: 999,
29
+ };
30
+ return creditModifier;
31
+ };
32
+ };
@@ -0,0 +1,25 @@
1
+ module.exports = ({ constants, actions, localization, utils }) => {
2
+ const { helpers } = utils;
3
+ const { Modifier } = constants;
4
+
5
+ return function createDiscountModifier(params) {
6
+ const { amount, type } = params;
7
+ const { formatAmount } = localization;
8
+
9
+ const name =
10
+ type === Modifier.Compute.Types.PERCENTAGE
11
+ ? `${amount}%`
12
+ : `${formatAmount(amount)}`;
13
+
14
+ return actions.create({
15
+ compute: {
16
+ action: Modifier.Compute.Actions.SUBTRACT,
17
+ amount,
18
+ type,
19
+ },
20
+ type: Modifier.Types.DISCOUNT,
21
+ name: `${name} ${Modifier.Types.DISCOUNT}`,
22
+ _id: helpers.getObjectID(),
23
+ });
24
+ };
25
+ };
@@ -0,0 +1,29 @@
1
+ module.exports = ({ actions }) =>
2
+ function createGroupValuesModifier({ modifier, value, add = false }) {
3
+ if (!modifier || !value || !actions.isGroupOfValues(modifier)) return null;
4
+
5
+ const multiSelect = !actions.isSingleValue(modifier);
6
+ let selectedValues = [];
7
+ const modifierValues = [...modifier.properties.group.values, value];
8
+
9
+ if (!add) {
10
+ selectedValues = [...(modifier.properties.group.selectedValues || [])];
11
+ const remove = selectedValues.includes(value);
12
+ if (remove)
13
+ selectedValues = selectedValues.filter(each => each !== value);
14
+ else if (multiSelect) selectedValues.push(value);
15
+ else selectedValues = [value];
16
+ }
17
+
18
+ return {
19
+ ...modifier,
20
+ properties: {
21
+ ...modifier.properties,
22
+ group: {
23
+ ...modifier.properties.group,
24
+ selectedValues,
25
+ values: add ? [...new Set(modifierValues)] : [],
26
+ },
27
+ },
28
+ };
29
+ };
@@ -0,0 +1,42 @@
1
+ /*
2
+ * create a distrubuted Modifier based on Order and Item
3
+ */
4
+ module.exports = ({ _, utils, constants, actions }) => {
5
+ const { math } = utils;
6
+ const { Modifier } = constants;
7
+
8
+ return function createIndirectModifier(
9
+ modifier,
10
+ options = { orderTotal: 0, itemTotal: 0, itemQuantity: 1 }
11
+ ) {
12
+ const { compute = {} } = modifier;
13
+ const { type, amount = 0 } = compute;
14
+ let modifierAmount = amount;
15
+
16
+ if (type === Modifier.Compute.Types.PERCENTAGE)
17
+ modifierAmount = math.div(math.mul(options.orderTotal, amount), 100);
18
+
19
+ let amountToApply = 0;
20
+
21
+ if (!math.isZero(options.orderTotal))
22
+ amountToApply = math.div(
23
+ math.mul(modifierAmount, options.itemTotal),
24
+ options.orderTotal,
25
+ options.itemQuantity
26
+ );
27
+
28
+ const modifierToAdd = actions.create({
29
+ ..._.cloneDeep(modifier),
30
+ direct: false,
31
+ compute: {
32
+ type: Modifier.Compute.Types.FIXED,
33
+ amount: amountToApply,
34
+ action: compute.action || Modifier.Compute.Actions.SUBTRACT,
35
+ },
36
+ });
37
+ if (actions.getProperty(modifierToAdd, 'maxAmount') !== null)
38
+ delete modifierToAdd.properties.maxAmount;
39
+
40
+ return modifierToAdd;
41
+ };
42
+ };
@@ -0,0 +1,19 @@
1
+ module.exports = ({ constants, actions, utils }) => {
2
+ const { Modifier } = constants;
3
+ const { helpers } = utils;
4
+
5
+ return function createSubscriptionModifier(params = {}) {
6
+ return actions.create({
7
+ compute: {
8
+ action: Modifier.Compute.Actions.SUBTRACT,
9
+ type: Modifier.Compute.Types.FIXED,
10
+ amount: params.amount,
11
+ },
12
+ attributes: [Modifier.Attributes.SUBSCRIPTION],
13
+ name: Modifier.Attributes.SUBSCRIPTION,
14
+ type: Modifier.Types.DISCOUNT,
15
+ _id: helpers.getObjectID(),
16
+ ...params,
17
+ });
18
+ };
19
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = () =>
2
+ function displayAsCard(modifier) {
3
+ return !!(
4
+ modifier &&
5
+ modifier.properties &&
6
+ modifier.properties.group &&
7
+ modifier.properties.group.displayType === 'card'
8
+ );
9
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = () =>
2
+ function displayAsChips(modifier) {
3
+ return !!(
4
+ modifier &&
5
+ modifier.properties &&
6
+ modifier.properties.group &&
7
+ modifier.properties.group.displayType === 'chips'
8
+ );
9
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = () =>
2
+ function displayAsList(modifier) {
3
+ return !!(
4
+ modifier &&
5
+ modifier.properties &&
6
+ modifier.properties.group &&
7
+ modifier.properties.group.displayType === 'list'
8
+ );
9
+ };
@@ -0,0 +1,12 @@
1
+ module.exports = ({ utils }) => {
2
+ const { helpers } = utils;
3
+ return function duplicate(modifier) {
4
+ if (!modifier) return null;
5
+
6
+ return {
7
+ ...modifier,
8
+ modifierId: modifier.modifierId || modifier._id,
9
+ _id: helpers.getObjectID(),
10
+ };
11
+ };
12
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = () =>
2
+ function enableAutoPopup(modifier) {
3
+ return !!(
4
+ modifier &&
5
+ modifier.properties &&
6
+ modifier.properties.group &&
7
+ modifier.properties.group.enableAutoPopup
8
+ );
9
+ };
@@ -0,0 +1,4 @@
1
+ module.exports = () =>
2
+ function filterByRequiredModifiers(modifiers) {
3
+ return modifiers.filter(each => each.required);
4
+ };
@@ -0,0 +1,7 @@
1
+ module.exports = () =>
2
+ function findById(modifiers, id) {
3
+ if (!Array.isArray(modifiers)) return null;
4
+ return modifiers
5
+ .filter(Boolean)
6
+ .find(each => each._id === id || each.modifierId === id);
7
+ };
@@ -0,0 +1,10 @@
1
+ module.exports = ({ actions }) =>
2
+ function findByPaymentMethod({ modifiers, paymentMethod = '' }) {
3
+ if (!Array.isArray(modifiers) || !paymentMethod) return null;
4
+
5
+ return modifiers.find(
6
+ each =>
7
+ actions.isPaymentMethods(each) &&
8
+ each.conditions.paymentMethods.includes(paymentMethod)
9
+ );
10
+ };
@@ -0,0 +1,10 @@
1
+ module.exports = ({ actions }) =>
2
+ function findByPaymentType({ modifiers, paymentType = '' }) {
3
+ if (!Array.isArray(modifiers) || !paymentType) return null;
4
+
5
+ return modifiers.find(
6
+ each =>
7
+ actions.isPaymentTypes(each) &&
8
+ each.conditions.paymentTypes.includes(paymentType)
9
+ );
10
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = ({ actions }) =>
2
+ function getAvailablePromotions(modifiers) {
3
+ if (!Array.isArray(modifiers)) return [];
4
+ return modifiers.filter(each => actions.isAvailablePromotion(each));
5
+ };
@@ -0,0 +1,15 @@
1
+ module.exports = ({ actions }) =>
2
+ /*
3
+ * This function will receive a list of promotion modifiers and filter them by the limits that we have for promotions
4
+ * Filters are:
5
+ * modifier.properties.promotion.dateLimit.{from, to} which compares today with these two dates
6
+ * modifier.properties.promotion.numberOfUsesLimit which will be checked with modifier.properties.promotion.numberOfUses
7
+ */
8
+ function getAvailablePromotionsOrSubscriptions(modifiers) {
9
+ if (!Array.isArray(modifiers)) return [];
10
+ return modifiers.filter(
11
+ each =>
12
+ actions.isAvailableSubscription(each) ||
13
+ actions.isAvailablePromotion(each)
14
+ );
15
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = ({ actions }) =>
2
+ function getAvailableSubscriptions(modifiers) {
3
+ if (!Array.isArray(modifiers)) return [];
4
+ return modifiers.filter(each => actions.isAvailableSubscription(each));
5
+ };
@@ -0,0 +1,6 @@
1
+ module.exports = ({ actions }) =>
2
+ //
3
+ function getByAttribute(modifiers, attribute) {
4
+ if (!modifiers) return [];
5
+ return modifiers.filter(each => actions.hasAttribute(each, attribute));
6
+ };
@@ -0,0 +1,6 @@
1
+ module.exports = ({ actions }) =>
2
+ //
3
+ function getCreditModifier(modifiers) {
4
+ if (!modifiers) return null;
5
+ return modifiers.find(actions.isCredit);
6
+ };
@@ -0,0 +1,4 @@
1
+ module.exports = ({ actions }) =>
2
+ function getDefaultModifiers(modifiers) {
3
+ return (modifiers || []).filter(each => actions.isDefault(each));
4
+ };
@@ -0,0 +1,10 @@
1
+ module.exports = () =>
2
+ function getDepartmentMaxItems(modifier) {
3
+ return (
4
+ (modifier &&
5
+ modifier.properties &&
6
+ modifier.properties.department &&
7
+ modifier.properties.department.maxItems) ||
8
+ 0
9
+ );
10
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = ({ actions, utils }) => {
2
+ const { math } = utils;
3
+ const getOrder = modifier => (modifier && modifier.order) || 0;
4
+
5
+ return function getDepartmentModifiers(modifiers) {
6
+ if (!modifiers || !Array.isArray(modifiers)) return [];
7
+ return modifiers
8
+ .filter(each => actions.isDepartment(each))
9
+ .sort((mod1, mod2) => math.sub(getOrder(mod1), getOrder(mod2)));
10
+ };
11
+ };
@@ -0,0 +1,6 @@
1
+ module.exports = () =>
2
+ function getDescription(modifier) {
3
+ return (
4
+ (modifier && modifier._computed && modifier._computed.description) || ''
5
+ );
6
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = ({ actions }) =>
2
+ function getDescriptions(modifiers) {
3
+ if (!Array.isArray(modifiers)) return '';
4
+
5
+ const descriptions = modifiers
6
+ .map(each => actions.getDescription(each))
7
+ .filter(Boolean);
8
+ return descriptions.join(', ');
9
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = ({ actions }) =>
2
+ function getDirectModifiers(modifiers) {
3
+ if (!Array.isArray(modifiers)) return [];
4
+ return modifiers.filter(each => actions.isDirect(each));
5
+ };
@@ -0,0 +1,7 @@
1
+ module.exports = ({ actions }) =>
2
+ function getDiscountModifiers(modifiers) {
3
+ if (!Array.isArray(modifiers)) return [];
4
+ return modifiers.filter(
5
+ each => actions.isDiscount(each) || actions.isCredit(each)
6
+ );
7
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = () =>
2
+ function getEntityModifiers(entity) {
3
+ if (!entity || !entity.modifiers || !entity.modifiers.length) return [];
4
+ return entity.modifiers.map(each => {
5
+ const modifierId = each.modifierId || each._id;
6
+ return {
7
+ ...each,
8
+ modifierId,
9
+ };
10
+ });
11
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = ({ actions }) =>
2
+ function getEntityPromotions({ modifiers, entity }) {
3
+ if (!entity) return [];
4
+ let entityModifiers = actions.getMatchTagsModifiers({
5
+ modifiers,
6
+ entity,
7
+ });
8
+ entityModifiers = actions.getUnhiddenModifiers(entityModifiers);
9
+ const promotions = actions.getAvailablePromotions(entityModifiers);
10
+ return promotions;
11
+ };
@@ -0,0 +1,14 @@
1
+ module.exports = ({ actions }) =>
2
+ function getExtendedTags(modifiers) {
3
+ if (!modifiers) return [];
4
+ const filteredModifiers = modifiers.filter(each =>
5
+ actions.isCustomerTagsExtend(each)
6
+ );
7
+ if (!filteredModifiers.length) return [];
8
+
9
+ const extendedTags = filteredModifiers.reduce(
10
+ (arr, each) => arr.concat(each.properties.department.customerTagsExtend),
11
+ []
12
+ );
13
+ return extendedTags;
14
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = ({ actions }) =>
2
+ function getFiles(modifier) {
3
+ if (!actions.isGroupOfValues(modifier)) return [];
4
+ return modifier.properties.group.files || [];
5
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = () =>
2
+ function getGroupModifiers({ modifier, includeParent = true }) {
3
+ const { properties } = modifier;
4
+ if (!properties || !properties.group) return [];
5
+ const { modifiers = [] } = properties.group;
6
+ const groupModifiers = [...modifiers];
7
+ if (includeParent) groupModifiers.push(modifier);
8
+ return groupModifiers.filter(Boolean);
9
+ };
@@ -0,0 +1,4 @@
1
+ module.exports = ({ actions }) =>
2
+ function getGroupOfItemsModifiers(modifiers = []) {
3
+ return modifiers.filter(each => actions.isGroupOfItems(each));
4
+ };
@@ -0,0 +1,26 @@
1
+ module.exports = ({ actions }) => {
2
+ const find = (modifiers = [], modifierId = '') =>
3
+ modifiers.find(each => each._id === modifierId);
4
+ // This method returns all modifiers which are referenced by a modifier
5
+ return function getGroupRelatedModifiers({ cache, modifier }) {
6
+ if (!modifier) return [];
7
+ const checkCache = Array.isArray(cache) && cache.length;
8
+ const modifiers = actions.getGroupModifiers({
9
+ modifier,
10
+ includeParent: false,
11
+ });
12
+
13
+ const groupModifiers = modifiers.reduce((arr, each) => {
14
+ if (!each || !each._id) return arr;
15
+ if (checkCache) {
16
+ const org = find(cache, each.modifierId || each._id);
17
+ if (org) arr.push(org);
18
+ }
19
+ return arr;
20
+ }, []);
21
+
22
+ if (actions.includesInGroup(modifier)) groupModifiers.unshift(modifier);
23
+
24
+ return groupModifiers;
25
+ };
26
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = ({ actions }) =>
2
+ function getImages(modifier) {
3
+ if (!actions.isGroupOfValues(modifier)) return [];
4
+ return modifier.properties.group.images || [];
5
+ };
@@ -0,0 +1,30 @@
1
+ module.exports = ({ actions }) => {
2
+ const isRelated = modifier => actions.isGroupOfItems(modifier);
3
+
4
+ return function getInheritedModifiers({ parentItem, childItem }) {
5
+ if (!parentItem || !childItem) return [];
6
+
7
+ const { addModifiers: parentModifiers } = parentItem;
8
+ const { addModifiers: childModifiers = [], _id } = childItem;
9
+ const modifiers = [...childModifiers];
10
+
11
+ const relatedItemModifier = parentModifiers.find(each => isRelated(each));
12
+ if (!relatedItemModifier) return modifiers;
13
+
14
+ const { properties = {} } = relatedItemModifier;
15
+ const items = (properties.group && properties.group.items) || [];
16
+
17
+ const relatedItem = items.find(each => each._id === _id);
18
+ if (!relatedItem) return [];
19
+
20
+ if (properties.inheritModifiers && parentModifiers.length) {
21
+ const inheritedModifiers = parentModifiers
22
+ .filter(each => !isRelated(each))
23
+ .map(each => actions.duplicate(each));
24
+
25
+ if (inheritedModifiers.length) modifiers.push(...inheritedModifiers);
26
+ }
27
+
28
+ return actions.purifyModifiers(modifiers);
29
+ };
30
+ };
@@ -0,0 +1,39 @@
1
+ module.exports = ({ actions, utils }) => {
2
+ const { helpers } = utils;
3
+ return function getItemModifiers({ modifiers, customer, cache }) {
4
+ const matchedModifiers = actions.getMatchTagsModifiers({
5
+ modifiers,
6
+ entity: customer,
7
+ });
8
+
9
+ const enabledModifiers = matchedModifiers.filter(
10
+ each =>
11
+ (actions.isDefault(each) || actions.isRequired(each)) &&
12
+ !(actions.isGroupOfValues(each) || actions.isGroupOfModifiers(each))
13
+ );
14
+
15
+ const relatedModifiers = enabledModifiers
16
+ .map(each =>
17
+ actions.getRelatedModifiers({
18
+ modifier: each,
19
+ modifiers,
20
+ })
21
+ )
22
+ .reduce((acc, val) => acc.concat(val), []);
23
+
24
+ const starchModifier = actions.getStarchModifier({
25
+ cache,
26
+ modifiers: enabledModifiers,
27
+ starch: customer && customer.properties && customer.properties.starch,
28
+ });
29
+
30
+ const itemModifiers = [...enabledModifiers, ...relatedModifiers];
31
+ if (starchModifier) itemModifiers.push(starchModifier);
32
+
33
+ return itemModifiers.map(each => ({
34
+ ...each,
35
+ modifierId: each.modifierId || each._id,
36
+ _id: helpers.getObjectID(),
37
+ }));
38
+ };
39
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = ({ actions }) =>
2
+ function getLaundryModifiers(modifiers = []) {
3
+ return modifiers.filter(
4
+ each =>
5
+ actions.isDepartment(each) &&
6
+ each.properties.department.code &&
7
+ each.properties.department.code.toLowerCase() === 'l'
8
+ );
9
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = ({ actions }) =>
2
+ function getMatchTagsModifiers({ modifiers, entity }) {
3
+ if (!Array.isArray(modifiers)) return [];
4
+
5
+ return modifiers.filter(each => {
6
+ const modifier = each.modifier || each;
7
+ return modifier && actions.hasMatchTags(modifier, entity);
8
+ });
9
+ };
@@ -0,0 +1,14 @@
1
+ module.exports = () =>
2
+ /*
3
+ * will check the entity to find the input modifier
4
+ * if it finds the modifier will return the index of modifier
5
+ * otherwise will return -1
6
+ * */
7
+ function getModifierIndex({ entity, modifier }) {
8
+ if (!entity || !modifier) return -1;
9
+ const { modifiers = [] } = entity;
10
+ const { _id } = modifier;
11
+ return modifiers.findIndex(
12
+ each => each.modifierId === _id || each._id === _id
13
+ );
14
+ };
@@ -0,0 +1,24 @@
1
+ module.exports = ({ actions, _ }) =>
2
+ /**
3
+ * This function is for fetching preference Modifiers
4
+ */
5
+ function getPreferences(modifiers) {
6
+ if (!Array.isArray(modifiers) || !modifiers.length) return [];
7
+
8
+ const preferences = modifiers.filter(modifier =>
9
+ actions.isPreferences(modifier)
10
+ );
11
+ if (!Array.isArray(preferences) || !preferences.length) return [];
12
+
13
+ const groups = preferences.map(modifier => modifier.group).filter(Boolean);
14
+ const sortedGroups = _.sortBy([...new Set(groups)]);
15
+
16
+ const categories = sortedGroups.map(name => ({
17
+ name,
18
+ modifiers: _.sortBy(
19
+ preferences.filter(each => each.group === name),
20
+ ['order']
21
+ ),
22
+ }));
23
+ return categories;
24
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = ({ actions }) =>
2
+ function getPromotionModifiers(modifiers) {
3
+ if (!Array.isArray(modifiers)) return [];
4
+ return modifiers.filter(each => actions.isPromotion(each));
5
+ };
@@ -0,0 +1,6 @@
1
+ module.exports = ({ actions }) =>
2
+ function getPromptMessage(modifier) {
3
+ return actions.hasDisplayPrompt(modifier)
4
+ ? modifier.properties.group.promptMessage
5
+ : null;
6
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = () =>
2
+ function getProperty(modifier, key) {
3
+ if (
4
+ modifier &&
5
+ modifier.properties &&
6
+ // eslint-disable-next-line no-prototype-builtins
7
+ modifier.properties.hasOwnProperty(key)
8
+ )
9
+ return modifier.properties[key];
10
+ return null;
11
+ };
@@ -0,0 +1,7 @@
1
+ module.exports = () =>
2
+ function getRecommendedModifiers(modifiers) {
3
+ return modifiers.filter(each => {
4
+ const modifier = each.modifier || each;
5
+ return modifier.recommended;
6
+ });
7
+ };
@@ -0,0 +1,10 @@
1
+ module.exports = ({ actions }) =>
2
+ function getRelatedModifiers({ modifier, modifiers }) {
3
+ if (!modifier || !modifier.addModifiers || !modifiers) return [];
4
+ // get related modifiers
5
+ const relatedModifiers = modifier.addModifiers
6
+ .map(each => actions.findById(modifiers, each._id))
7
+ .filter(Boolean);
8
+
9
+ return relatedModifiers;
10
+ };
@@ -0,0 +1,4 @@
1
+ module.exports = ({ actions }) =>
2
+ function getRequiredModifiers(modifiers) {
3
+ return modifiers.filter(each => actions.isRequired(each));
4
+ };
@@ -0,0 +1,7 @@
1
+ module.exports = ({ actions }) =>
2
+ function getSelectedValues(modifier) {
3
+ if (!actions.isGroupOfValues(modifier)) return null;
4
+ if (Array.isArray(modifier.properties.group.selectedValues))
5
+ return modifier.properties.group.selectedValues.join(', ');
6
+ return null;
7
+ };