@darkpos/pricing 1.0.43 → 1.0.44

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 (42) hide show
  1. package/__TEST__/item/getItemsModifierDescription.test.js +10 -3
  2. package/__TEST__/mocks/addItemMock.js +18729 -19357
  3. package/__TEST__/mocks/partially-paid/order-modifiers.json +48 -51
  4. package/__TEST__/mocks/partially-paid/order-partially-paid.json +893 -860
  5. package/__TEST__/mocks/unpaid/order-modifiers.json +48 -52
  6. package/__TEST__/modifier/calculate.test.js +1 -0
  7. package/__TEST__/modifier/getMatchTagsModifiers.test.js +72 -18
  8. package/__TEST__/modifier/getModifierIndex.test.js +10 -7
  9. package/__TEST__/modifier/getRecommendedModifiers.test.js +6 -4
  10. package/__TEST__/modifier/hasAttribute.test.js +11 -5
  11. package/__TEST__/modifier/hasMatchTags.test.js +33 -11
  12. package/__TEST__/modifier/sort.test.js +1 -1
  13. package/__TEST__/order/conditionsNotMet.test.js +133 -0
  14. package/__TEST__/order/order.test.js +7 -5
  15. package/__TEST__/order/pickEndDate.test.js +1 -1
  16. package/__TEST__/order/validateConditionsCalculate.test.js +397 -0
  17. package/lib/constants/index.js +1 -1
  18. package/lib/index.js +11 -2
  19. package/lib/item/calculate.js +27 -10
  20. package/lib/item/getItemModifiersDescription.js +1 -0
  21. package/lib/item/markModifiersAsLocked.js +3 -1
  22. package/lib/modifier/areConditionsMet.js +71 -0
  23. package/lib/modifier/index.js +14 -5
  24. package/lib/modifier/isPaymentMethodModifier.js +1 -1
  25. package/lib/modifier/isPaymentTypeModifier.js +1 -1
  26. package/lib/modifier/isValid.js +12 -0
  27. package/lib/modifier/validate.js +14 -0
  28. package/lib/modifier/validateDateDaysDiff.js +30 -0
  29. package/lib/modifier/validateInArr.js +12 -0
  30. package/lib/modifier/validateNumberCondition.js +20 -0
  31. package/lib/modifier/validateRequiredModifiers.js +16 -0
  32. package/lib/order/addItemModifier.js +72 -28
  33. package/lib/order/calculate.js +12 -7
  34. package/lib/order/index.js +0 -2
  35. package/lib/order/removeModifiersWithPaymentMethods.js +1 -2
  36. package/lib/order/removeModifiersWithPaymentTypes.js +1 -2
  37. package/lib/store/getRecommendedEndDate.js +13 -0
  38. package/lib/store/index.js +25 -0
  39. package/package.json +3 -3
  40. package/lib/modifier/findByPaymentMethod.js +0 -10
  41. package/lib/modifier/findByPaymentType.js +0 -10
  42. /package/lib/{order → store}/pickEndDate.js +0 -0
@@ -0,0 +1,397 @@
1
+ const usePricing = require('../../index');
2
+
3
+ const pricingService = usePricing();
4
+
5
+ describe('Conditions not met for the item', () => {
6
+ test('#1: Item pieces condition is not met, item price remains the same', () => {
7
+ const order = {
8
+ id: 'ord-123',
9
+ items: [],
10
+ modifiers: [],
11
+ };
12
+ const item = {
13
+ quantity: 1,
14
+ pieces: 1,
15
+ itemId: '123',
16
+ price: 100,
17
+ modifiers: [
18
+ {
19
+ compute: {
20
+ amount: 30,
21
+ type: 'fixed',
22
+ action: 'substract',
23
+ },
24
+ conditions: {
25
+ rules: [
26
+ {
27
+ key: 'itemPieces',
28
+ value: 5,
29
+ operand: '$gt',
30
+ },
31
+ ],
32
+ },
33
+ },
34
+ ],
35
+ };
36
+ order.items.push(item);
37
+ const { calculate } = pricingService.order;
38
+ // Calculate the order
39
+ const calculatedOrder = calculate(order);
40
+ expect(calculatedOrder).toHaveProperty('total', 100);
41
+ expect(calculatedOrder).toHaveProperty('subTotal', 100);
42
+ });
43
+ test('#2: Item pieces condition is met, item total is updated', () => {
44
+ const order = {
45
+ id: 'ord-123',
46
+ items: [],
47
+ modifiers: [],
48
+ };
49
+ const item = {
50
+ quantity: 1,
51
+ pieces: 6,
52
+ itemId: '123',
53
+ price: 100,
54
+ modifiers: [
55
+ {
56
+ compute: {
57
+ amount: 30,
58
+ type: 'fixed',
59
+ action: 'subtract',
60
+ },
61
+ conditions: {
62
+ rules: [
63
+ {
64
+ key: 'itemPieces',
65
+ value: 5,
66
+ operand: '$gt',
67
+ },
68
+ ],
69
+ },
70
+ },
71
+ ],
72
+ };
73
+ order.items.push(item);
74
+ const { calculate } = pricingService.order;
75
+ // Calculate the order
76
+
77
+ const calculatedOrder = calculate(order);
78
+ expect(calculatedOrder).toHaveProperty('total', 70);
79
+ expect(calculatedOrder).toHaveProperty('subTotal', 100);
80
+ });
81
+ test('#3: Required modifiers condition is not met, item price remains the same', () => {
82
+ const order = {
83
+ id: 'ord-123',
84
+ items: [],
85
+ modifiers: [],
86
+ };
87
+ const item = {
88
+ quantity: 1,
89
+ itemId: '123',
90
+ price: 100,
91
+ modifiers: [],
92
+ };
93
+ order.items.push(item);
94
+ const modifier = {
95
+ conditions: {
96
+ rules: [
97
+ {
98
+ key: 'modifiers',
99
+ value: [{ _id: 'mod-1' }],
100
+ operand: '$in',
101
+ },
102
+ ],
103
+ },
104
+ compute: {
105
+ amount: 30,
106
+ type: 'fixed',
107
+ action: 'subtract',
108
+ },
109
+ };
110
+ item.modifiers.push(modifier);
111
+ const { calculate } = pricingService.order;
112
+ // Calculate the order
113
+ const calculatedOrder = calculate(order);
114
+ expect(calculatedOrder).toHaveProperty('total', 100);
115
+ expect(calculatedOrder).toHaveProperty('subTotal', 100);
116
+ });
117
+ test('#4: Required modifiers condition is met, item total is updated', () => {
118
+ const order = {
119
+ id: 'ord-123',
120
+ items: [],
121
+ modifiers: [],
122
+ };
123
+ const item = {
124
+ quantity: 1,
125
+ itemId: '123',
126
+ price: 100,
127
+ modifiers: [],
128
+ };
129
+ const modifierToValidate = {
130
+ _id: 'mod-1',
131
+ };
132
+
133
+ const modifier = {
134
+ conditions: {
135
+ rules: [
136
+ {
137
+ key: 'modifiers',
138
+ value: [{ modifierId: 'mod-1' }],
139
+ operand: '$in',
140
+ },
141
+ ],
142
+ },
143
+ compute: {
144
+ amount: 30,
145
+ type: 'fixed',
146
+ action: 'subtract',
147
+ },
148
+ };
149
+ item.modifiers.push(modifierToValidate);
150
+ item.modifiers.push(modifier);
151
+ order.items.push(item);
152
+ const { calculate } = pricingService.order;
153
+ const calculatedOrder = calculate(order);
154
+ expect(calculatedOrder).toHaveProperty('total', 70);
155
+ expect(calculatedOrder).toHaveProperty('subTotal', 100);
156
+ });
157
+ test('#5: endDateDays condition is not met, item price remains the same', () => {
158
+ const order = {
159
+ id: 'ord-123',
160
+ items: [],
161
+ modifiers: [],
162
+ start: {
163
+ requestDate: new Date('2020-01-01'),
164
+ },
165
+ end: {
166
+ requestDate: new Date('2020-01-02'),
167
+ },
168
+ };
169
+ const item = {
170
+ quantity: 1,
171
+ itemId: '123',
172
+ price: 100,
173
+ modifiers: [],
174
+ };
175
+ order.items.push(item);
176
+ const modifier = {
177
+ conditions: {
178
+ rules: [
179
+ {
180
+ key: 'endDateDays',
181
+ value: 5,
182
+ operand: '$gt',
183
+ },
184
+ ],
185
+ },
186
+ compute: {
187
+ amount: 30,
188
+ type: 'fixed',
189
+ action: 'subtract',
190
+ },
191
+ };
192
+ item.modifiers.push(modifier);
193
+ const { calculate } = pricingService.order;
194
+ // Calculate the order
195
+ const calculatedOrder = calculate(order);
196
+ expect(calculatedOrder).toHaveProperty('total', 100);
197
+ expect(calculatedOrder).toHaveProperty('subTotal', 100);
198
+ });
199
+ test('#6: endDateDays condition is met, item total is updated', () => {
200
+ const order = {
201
+ id: 'ord-123',
202
+ items: [],
203
+ modifiers: [],
204
+ start: {
205
+ requestDate: new Date('2020-01-01'),
206
+ },
207
+ end: {
208
+ requestDate: new Date('2020-01-08'),
209
+ },
210
+ };
211
+ const item = {
212
+ quantity: 1,
213
+ itemId: '123',
214
+ price: 100,
215
+ modifiers: [],
216
+ };
217
+ order.items.push(item);
218
+ const modifier = {
219
+ compute: {
220
+ amount: 30,
221
+ type: 'fixed',
222
+ action: 'subtract',
223
+ },
224
+ conditions: {
225
+ rules: [
226
+ {
227
+ key: 'endDateDays',
228
+ value: 5,
229
+ operand: '$gt',
230
+ },
231
+ ],
232
+ },
233
+ };
234
+ item.modifiers.push(modifier);
235
+ const { calculate } = pricingService.order;
236
+ // Calculate the order
237
+ const calculatedOrder = calculate(order);
238
+ expect(calculatedOrder).toHaveProperty('total', 70);
239
+ expect(calculatedOrder).toHaveProperty('subTotal', 100);
240
+ });
241
+ // Do tests for paymentMethods and paymentTypes
242
+ test('#7: paymentMethods condition is not met, item price remains the same', () => {
243
+ const order = {
244
+ id: 'ord-123',
245
+ items: [],
246
+ modifiers: [],
247
+ };
248
+ const item = {
249
+ quantity: 1,
250
+ itemId: '123',
251
+ price: 100,
252
+ modifiers: [],
253
+ };
254
+ order.items.push(item);
255
+ const modifier = {
256
+ conditions: {
257
+ rules: [
258
+ {
259
+ key: 'paymentMethods',
260
+ value: ['cash'],
261
+ operand: '$in',
262
+ },
263
+ ],
264
+ },
265
+ compute: {
266
+ amount: 30,
267
+ type: 'fixed',
268
+ action: 'subtract',
269
+ },
270
+ };
271
+ item.modifiers.push(modifier);
272
+ const { calculate } = pricingService.order;
273
+ const paymentMethod = {
274
+ key: 'credit',
275
+ };
276
+ const calculatedOrder = calculate(order, { paymentMethod });
277
+ expect(calculatedOrder).toHaveProperty('total', 100);
278
+ expect(calculatedOrder).toHaveProperty('subTotal', 100);
279
+ });
280
+ test('#8: paymentMethods condition is met, item total is updated', () => {
281
+ const order = {
282
+ id: 'ord-123',
283
+ items: [],
284
+ modifiers: [],
285
+ };
286
+ const item = {
287
+ quantity: 1,
288
+ itemId: '123',
289
+ price: 100,
290
+ modifiers: [],
291
+ };
292
+ order.items.push(item);
293
+ const modifier = {
294
+ conditions: {
295
+ rules: [
296
+ {
297
+ key: 'paymentMethods',
298
+ value: ['cash'],
299
+ operand: '$in',
300
+ },
301
+ ],
302
+ },
303
+ compute: {
304
+ amount: 30,
305
+ type: 'fixed',
306
+ action: 'subtract',
307
+ },
308
+ };
309
+ item.modifiers.push(modifier);
310
+ const { calculate } = pricingService.order;
311
+ // Calculate the order
312
+ const paymentMethod = {
313
+ key: 'cash',
314
+ };
315
+ const calculatedOrder = calculate(order, { paymentMethod });
316
+ expect(calculatedOrder).toHaveProperty('total', 70);
317
+ expect(calculatedOrder).toHaveProperty('subTotal', 100);
318
+ });
319
+ test('#9: paymentTypes condition is not met, item price remains the same', () => {
320
+ const order = {
321
+ id: 'ord-123',
322
+ items: [],
323
+ modifiers: [],
324
+ };
325
+ const item = {
326
+ quantity: 1,
327
+ itemId: '123',
328
+ price: 100,
329
+ modifiers: [],
330
+ };
331
+ order.items.push(item);
332
+ const modifier = {
333
+ conditions: {
334
+ rules: [
335
+ {
336
+ key: 'paymentTypes',
337
+ value: ['cash'],
338
+ operand: '$in',
339
+ },
340
+ ],
341
+ },
342
+ compute: {
343
+ amount: 30,
344
+ type: 'fixed',
345
+ action: 'subtract',
346
+ },
347
+ };
348
+ item.modifiers.push(modifier);
349
+ const { calculate } = pricingService.order;
350
+ const paymentMethod = {
351
+ type: 'credit',
352
+ };
353
+ // Calculate the order
354
+ const calculatedOrder = calculate(order, { paymentMethod });
355
+ expect(calculatedOrder).toHaveProperty('total', 100);
356
+ expect(calculatedOrder).toHaveProperty('subTotal', 100);
357
+ });
358
+ test('#10: paymentTypes condition is met, item total is updated', () => {
359
+ const order = {
360
+ id: 'ord-123',
361
+ items: [],
362
+ modifiers: [],
363
+ };
364
+ const item = {
365
+ quantity: 1,
366
+ itemId: '123',
367
+ price: 100,
368
+ modifiers: [],
369
+ };
370
+ order.items.push(item);
371
+ const modifier = {
372
+ conditions: {
373
+ rules: [
374
+ {
375
+ key: 'paymentTypes',
376
+ value: ['cash'],
377
+ operand: '$in',
378
+ },
379
+ ],
380
+ },
381
+ compute: {
382
+ amount: 30,
383
+ type: 'fixed',
384
+ action: 'subtract',
385
+ },
386
+ };
387
+ item.modifiers.push(modifier);
388
+ const { calculate } = pricingService.order;
389
+ // Calculate the order
390
+ const paymentMethod = {
391
+ type: 'cash',
392
+ };
393
+ const calculatedOrder = calculate(order, { paymentMethod });
394
+ expect(calculatedOrder).toHaveProperty('total', 70);
395
+ expect(calculatedOrder).toHaveProperty('subTotal', 100);
396
+ });
397
+ });
@@ -1,4 +1,4 @@
1
- const Status = require('./status');
1
+ const Status = require('./Status');
2
2
  const Modifier = require('./Modifier');
3
3
 
4
4
  module.exports = {
package/lib/index.js CHANGED
@@ -2,6 +2,7 @@ const utils = require('@darkpos/utils');
2
2
  const _ = require('lodash');
3
3
  const moment = require('moment-timezone');
4
4
  /** services */
5
+ const makeStoreActions = require('./store');
5
6
  const makeItemActions = require('./item');
6
7
  const makeOrderActions = require('./order');
7
8
  const makeModifierActions = require('./modifier');
@@ -22,18 +23,26 @@ module.exports = session => {
22
23
  };
23
24
 
24
25
  //
25
- const modifierActions = makeModifierActions(deps);
26
- const itemActions = makeItemActions({ ...deps, modifierActions });
26
+ // general actions
27
+ const storeActions = makeStoreActions(deps);
28
+ const modifierActions = makeModifierActions({ ...deps, storeActions });
29
+ const itemActions = makeItemActions({
30
+ ...deps,
31
+ modifierActions,
32
+ storeActions,
33
+ });
27
34
  const orderActions = makeOrderActions({
28
35
  ...deps,
29
36
  itemActions,
30
37
  modifierActions,
38
+ storeActions,
31
39
  });
32
40
 
33
41
  return {
34
42
  item: itemActions,
35
43
  order: orderActions,
36
44
  modifier: modifierActions,
45
+ store: storeActions,
37
46
  constants,
38
47
  };
39
48
  };
@@ -3,9 +3,11 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
3
3
  const { math } = utils;
4
4
  //
5
5
  const { getComputeModField } = require('../modifier/utils');
6
-
7
- const calculateOne = inputItem => {
6
+ const calculateOne = (inputItem, opts = {}) => {
8
7
  const item = _.cloneDeep(inputItem);
8
+ const paymentMethod = opts.paymentMethod || null;
9
+ const startRequestDate = opts.startRequestDate || null;
10
+ const endRequestDate = opts.endRequestDate || null;
9
11
  if (!item) return item;
10
12
 
11
13
  const subTotals = {
@@ -23,17 +25,31 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
23
25
 
24
26
  const modifiers = [];
25
27
  const { modifiers: itemModifiers = [] } = item;
26
- const amountOverride = itemModifiers.find(each =>
28
+
29
+ const validatedModifiers = itemModifiers.map(each =>
30
+ modifierActions.validate(each, {
31
+ item,
32
+ paymentMethod,
33
+ startRequestDate,
34
+ endRequestDate,
35
+ })
36
+ );
37
+
38
+ const amountOverride = validatedModifiers.find(each =>
27
39
  modifierActions.isAmountOverride(each)
28
40
  );
29
41
 
30
- const modifiersToCompute = itemModifiers.filter(
42
+ const modifiersToCompute = validatedModifiers.filter(
31
43
  each =>
32
- !modifierActions.isOverride(each) && each.compute && each.compute.type
44
+ !modifierActions.isOverride(each) &&
45
+ each.compute &&
46
+ each.compute.type &&
47
+ modifierActions.isValid(each)
33
48
  );
49
+
34
50
  if (amountOverride) modifiersToCompute.push(amountOverride);
35
51
 
36
- const modifiersToNotCompute = itemModifiers
52
+ const modifiersToNotCompute = validatedModifiers
37
53
  .filter(
38
54
  each =>
39
55
  !modifiersToCompute.find(
@@ -113,10 +129,11 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
113
129
  };
114
130
 
115
131
  //
116
- const calculateMany = (items = []) => items.map(item => calculateOne(item));
132
+ const calculateMany = (items = [], opts = null) =>
133
+ items.map(item => calculateOne(item, opts));
117
134
 
118
- return function calculate(item) {
119
- if (Array.isArray(item)) return calculateMany(item);
120
- return calculateOne(item);
135
+ return function calculate(item, opts) {
136
+ if (Array.isArray(item)) return calculateMany(item, opts);
137
+ return calculateOne(item, opts);
121
138
  };
122
139
  };
@@ -7,6 +7,7 @@ module.exports = ({ modifierActions, _, settings }) =>
7
7
  .filter(
8
8
  each =>
9
9
  !modifierActions.isHidden(each) &&
10
+ modifierActions.isValid(each) &&
10
11
  !modifierActions.isAmountOverride(each) &&
11
12
  !modifierActions.isDepartment(each) &&
12
13
  modifierActions.isDirect(each)
@@ -5,7 +5,9 @@ module.exports = () =>
5
5
  return {
6
6
  ...item,
7
7
  modifiers: item.modifiers.map(mod =>
8
- modifierIds.includes(mod._parentId) ? { ...mod, locked: true } : mod
8
+ modifierIds.includes(mod._parentId || mod._id)
9
+ ? { ...mod, locked: true }
10
+ : mod
9
11
  ),
10
12
  };
11
13
  };
@@ -0,0 +1,71 @@
1
+ module.exports = ({ actions }) => {
2
+ const modifierConditionPass = (
3
+ modifier,
4
+ { item, paymentMethod, startRequestDate, endRequestDate }
5
+ ) =>
6
+ modifier.conditions && Array.isArray(modifier.conditions.rules)
7
+ ? modifier.conditions.rules.every(condition => {
8
+ switch (condition.key) {
9
+ case 'itemPieces':
10
+ return actions.validateNumberCondition(
11
+ item.pieces,
12
+ condition.value,
13
+ condition.operand
14
+ );
15
+ case 'itemQuantity':
16
+ return actions.validateNumberCondition(
17
+ item.quantity,
18
+ condition.value,
19
+ condition.operand
20
+ );
21
+ case 'modifiers':
22
+ return actions.validateRequiredModifiers(
23
+ item.modifiers,
24
+ condition.value,
25
+ condition.operand
26
+ );
27
+ case 'endDateDays':
28
+ return actions.validateDateDaysDiff(
29
+ startRequestDate,
30
+ endRequestDate,
31
+ condition.value,
32
+ condition.operand
33
+ );
34
+ case 'paymentMethods':
35
+ return actions.validateInArr(
36
+ paymentMethod ? paymentMethod.key : null,
37
+ condition.value,
38
+ condition.operand
39
+ );
40
+ case 'paymentTypes':
41
+ return actions.validateInArr(
42
+ paymentMethod ? paymentMethod.type : null,
43
+ condition.value,
44
+ condition.operand
45
+ );
46
+ default:
47
+ return false;
48
+ }
49
+ }) || modifier.locked
50
+ : true;
51
+
52
+ function areConditionsMet(modifier, opts) {
53
+ const {
54
+ item = null,
55
+ paymentMethod = null,
56
+ endRequestDate = null,
57
+ startRequestDate = null,
58
+ } = opts;
59
+ // const recommendedEndDate = storeActions.getRecommendedEndDate();
60
+ return (
61
+ modifier &&
62
+ modifierConditionPass(modifier, {
63
+ item,
64
+ paymentMethod,
65
+ startRequestDate,
66
+ endRequestDate,
67
+ })
68
+ );
69
+ }
70
+ return areConditionsMet;
71
+ };
@@ -19,8 +19,6 @@ const duplicate = require('./duplicate');
19
19
  const enableAutoPopup = require('./enableAutoPopup');
20
20
  const filterByRequiredModifiers = require('./filterByRequiredModifiers');
21
21
  const findById = require('./findById');
22
- const findByPaymentMethod = require('./findByPaymentMethod');
23
- const findByPaymentType = require('./findByPaymentType');
24
22
  const getAvailablePromotions = require('./getAvailablePromotions');
25
23
  const getAvailablePromotionsOrSubscriptions = require('./getAvailablePromotionsOrSubscriptions');
26
24
  const getAvailableSubscriptions = require('./getAvailableSubscriptions');
@@ -82,6 +80,7 @@ const isDirect = require('./isDirect');
82
80
  const hasNoTags = require('./hasNoTags');
83
81
  const isRemoveModifier = require('./isRemoveModifier');
84
82
  const isGroupOfModifiers = require('./isGroupOfModifiers');
83
+ const areConditionsMet = require('./areConditionsMet');
85
84
  const isRequiredAndOverride = require('./isRequiredAndOverride');
86
85
  const isManual = require('./isManual');
87
86
  const isPriceOverride = require('./isPriceOverride');
@@ -102,6 +101,7 @@ const isDefault = require('./isDefault');
102
101
  const isIncluded = require('./isIncluded');
103
102
  const isCustomerTagsExtend = require('./isCustomerTagsExtend');
104
103
  const isAmountOverride = require('./isAmountOverride');
104
+ const isValid = require('./isValid');
105
105
  const isDiscount = require('./isDiscount');
106
106
  const isHidden = require('./isHidden');
107
107
  const isIgnoreQuantity = require('./isIgnoreQuantity');
@@ -124,7 +124,6 @@ const isFixedAdd = require('./isFixedAdd');
124
124
  const isFee = require('./isFee');
125
125
  const isAdd = require('./isAdd');
126
126
  const mutateModifier = require('./mutateModifier');
127
-
128
127
  const isFixedDiscount = require('./isFixedDiscount');
129
128
  const removeLocked = require('./removeLocked');
130
129
  const hasItems = require('./hasItems');
@@ -133,6 +132,11 @@ const getGroupedModifiers = require('./getGroupedModifiers');
133
132
  const getNotesToModifierTags = require('./getNotesToModifierTags');
134
133
  const isOptionsOverride = require('./isOptionsOverride');
135
134
  const getGroupedModifierLabels = require('./getGroupedModifierLabels');
135
+ const validate = require('./validate');
136
+ const validateNumberCondition = require('./validateNumberCondition');
137
+ const validateRequiredModifiers = require('./validateRequiredModifiers');
138
+ const validateDateDaysDiff = require('./validateDateDaysDiff');
139
+ const validateInArr = require('./validateInArr');
136
140
 
137
141
  const modifierActions = (deps = {}) => {
138
142
  const actions = {};
@@ -163,8 +167,6 @@ const modifierActions = (deps = {}) => {
163
167
  enableAutoPopup: enableAutoPopup(innerDeps),
164
168
  filterByRequiredModifiers: filterByRequiredModifiers(innerDeps),
165
169
  findById: findById(innerDeps),
166
- findByPaymentMethod: findByPaymentMethod(innerDeps),
167
- findByPaymentType: findByPaymentType(innerDeps),
168
170
  getAvailablePromotions: getAvailablePromotions(innerDeps),
169
171
  getAvailablePromotionsOrSubscriptions:
170
172
  getAvailablePromotionsOrSubscriptions(innerDeps),
@@ -247,6 +249,7 @@ const modifierActions = (deps = {}) => {
247
249
  isDefault: isDefault(innerDeps),
248
250
  isCustomerTagsExtend: isCustomerTagsExtend(innerDeps),
249
251
  isAmountOverride: isAmountOverride(innerDeps),
252
+ isValid: isValid(innerDeps),
250
253
  isDiscount: isDiscount(innerDeps),
251
254
  isHidden: isHidden(innerDeps),
252
255
  isIgnoreQuantity: isIgnoreQuantity(innerDeps),
@@ -277,6 +280,12 @@ const modifierActions = (deps = {}) => {
277
280
  getNotesToModifierTags: getNotesToModifierTags(innerDeps),
278
281
  isOptionsOverride: isOptionsOverride(innerDeps),
279
282
  getGroupedModifierLabels: getGroupedModifierLabels(innerDeps),
283
+ validate: validate(innerDeps),
284
+ validateNumberCondition: validateNumberCondition(innerDeps),
285
+ validateRequiredModifiers: validateRequiredModifiers(innerDeps),
286
+ validateDateDaysDiff: validateDateDaysDiff(innerDeps),
287
+ validateInArr: validateInArr(innerDeps),
288
+ areConditionsMet: areConditionsMet(innerDeps),
280
289
  });
281
290
 
282
291
  Object.keys(freezedActions).forEach(actionName => {
@@ -3,6 +3,6 @@ module.exports = () =>
3
3
  return !!(
4
4
  modifier &&
5
5
  modifier.conditions &&
6
- (modifier.conditions.paymentMethods || []).length > 0
6
+ modifier.conditions.some(condition => condition.key === 'paymentMethods')
7
7
  );
8
8
  };
@@ -3,6 +3,6 @@ module.exports = () =>
3
3
  return !!(
4
4
  modifier &&
5
5
  modifier.conditions &&
6
- (modifier.conditions.paymentTypes || []).length > 0
6
+ modifier.conditions.some(condition => condition.key === 'paymentTypes')
7
7
  );
8
8
  };
@@ -0,0 +1,12 @@
1
+ module.exports = () =>
2
+ function isValid(modifier) {
3
+ if (
4
+ !modifier ||
5
+ !modifier.conditions ||
6
+ modifier.conditions.valid === undefined ||
7
+ modifier.conditions.valid === null
8
+ )
9
+ return true;
10
+
11
+ return !!modifier.conditions.valid;
12
+ };