@darkpos/pricing 1.0.41 → 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 (51) hide show
  1. package/__TEST__/item/getItemsModifierDescription.test.js +148 -0
  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/getGroupedModifierLabels.test.js +95 -0
  8. package/__TEST__/modifier/getGroupedModifiers.test.js +65 -0
  9. package/__TEST__/modifier/getMatchTagsModifiers.test.js +72 -18
  10. package/__TEST__/modifier/getModifierIndex.test.js +10 -7
  11. package/__TEST__/modifier/getNotesToModifierTags.test.js +78 -0
  12. package/__TEST__/modifier/getRecommendedModifiers.test.js +6 -4
  13. package/__TEST__/modifier/hasAttribute.test.js +11 -5
  14. package/__TEST__/modifier/hasMatchTags.test.js +33 -11
  15. package/__TEST__/modifier/isOptionsOverride.test.js +46 -0
  16. package/__TEST__/modifier/sort.test.js +1 -1
  17. package/__TEST__/order/conditionsNotMet.test.js +133 -0
  18. package/__TEST__/order/order.test.js +7 -5
  19. package/__TEST__/order/pickEndDate.test.js +4 -4
  20. package/__TEST__/order/validateConditionsCalculate.test.js +397 -0
  21. package/lib/constants/index.js +1 -1
  22. package/lib/index.js +11 -2
  23. package/lib/item/calculate.js +27 -10
  24. package/lib/item/getItemModifiersDescription.js +40 -7
  25. package/lib/item/markModifiersAsLocked.js +3 -1
  26. package/lib/modifier/areConditionsMet.js +71 -0
  27. package/lib/modifier/getGroupedModifierLabels.js +10 -0
  28. package/lib/modifier/getGroupedModifiers.js +21 -0
  29. package/lib/modifier/getNotesToModifierTags.js +21 -0
  30. package/lib/modifier/index.js +22 -5
  31. package/lib/modifier/isOptionsOverride.js +9 -0
  32. package/lib/modifier/isPaymentMethodModifier.js +1 -1
  33. package/lib/modifier/isPaymentTypeModifier.js +1 -1
  34. package/lib/modifier/isValid.js +12 -0
  35. package/lib/modifier/validate.js +14 -0
  36. package/lib/modifier/validateDateDaysDiff.js +30 -0
  37. package/lib/modifier/validateInArr.js +12 -0
  38. package/lib/modifier/validateNumberCondition.js +20 -0
  39. package/lib/modifier/validateRequiredModifiers.js +16 -0
  40. package/lib/order/addItemModifier.js +72 -28
  41. package/lib/order/calculate.js +12 -7
  42. package/lib/order/index.js +0 -2
  43. package/lib/order/removeModifiersWithPaymentMethods.js +1 -2
  44. package/lib/order/removeModifiersWithPaymentTypes.js +1 -2
  45. package/lib/store/getRecommendedEndDate.js +13 -0
  46. package/lib/store/index.js +25 -0
  47. package/lib/store/pickEndDate.js +62 -0
  48. package/package.json +3 -3
  49. package/lib/modifier/findByPaymentMethod.js +0 -10
  50. package/lib/modifier/findByPaymentType.js +0 -10
  51. package/lib/order/pickEndDate.js +0 -65
@@ -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
  };
@@ -1,22 +1,55 @@
1
- module.exports = ({ modifierActions }) =>
1
+ module.exports = ({ modifierActions, _, settings }) =>
2
2
  function getItemModifiersDescription(item) {
3
+ const groupModifiers =
4
+ settings && settings.order && settings.order.groupModifiers;
3
5
  if (!item || !Array.isArray(item.modifiers)) return [];
4
- const description = item.modifiers
6
+ let description = item.modifiers
5
7
  .filter(
6
8
  each =>
7
9
  !modifierActions.isHidden(each) &&
10
+ modifierActions.isValid(each) &&
8
11
  !modifierActions.isAmountOverride(each) &&
12
+ !modifierActions.isDepartment(each) &&
9
13
  modifierActions.isDirect(each)
10
14
  )
11
15
  .map(modifier => {
12
- const { name } = modifier;
16
+ const { name, _id, compute = {} } = modifier;
13
17
  let label = name;
14
18
  if (modifierActions.isGroupOfValues(modifier))
15
19
  label = modifierActions.getSelectedValues(modifier) || label;
20
+ const selectedOverrideOptions = _.get(
21
+ modifier,
22
+ 'properties.override.selected'
23
+ );
24
+ if (
25
+ modifier &&
26
+ !modifier.included &&
27
+ modifier._computed &&
28
+ modifier._computed.description
29
+ ) {
30
+ label = modifier._computed.description;
31
+ }
16
32
 
17
- return label;
18
- })
19
- .join(', ');
33
+ const modifierValue = {
34
+ label,
35
+ value: _id,
36
+ data: modifier,
37
+ quantity: 1,
38
+ };
20
39
 
21
- return description;
40
+ if (selectedOverrideOptions) {
41
+ modifierValue.label = `${name} ${compute.amount} ${selectedOverrideOptions.selectedUnit}`;
42
+ modifierValue.quantity = 0;
43
+ }
44
+ return modifierValue;
45
+ });
46
+ if (groupModifiers) {
47
+ description = modifierActions.getGroupedModifiers(description);
48
+ }
49
+
50
+ const descriptions = modifierActions.getNotesToModifierTags({
51
+ notes: item.notes,
52
+ modifierTags: description,
53
+ });
54
+ return descriptions;
22
55
  };
@@ -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
+ };
@@ -0,0 +1,10 @@
1
+ module.exports = ({ actions }) =>
2
+ function getGroupedModifierLabels(modifiers) {
3
+ const gModifiers = modifiers.map(modifier => ({
4
+ label: modifier.name,
5
+ value: modifier.modifierId,
6
+ data: modifier,
7
+ quantity: 1,
8
+ }));
9
+ return actions.getGroupedModifiers(gModifiers).map(tag => tag.label);
10
+ };
@@ -0,0 +1,21 @@
1
+ module.exports = () =>
2
+ function getGroupedModifiers(tags) {
3
+ return tags
4
+ .reduce((acc, curr) => {
5
+ const found = acc.find(
6
+ item => item.data.modifierId === curr.data.modifierId
7
+ );
8
+
9
+ if (found) {
10
+ found.quantity += 1;
11
+ } else {
12
+ acc.push({ ...curr });
13
+ }
14
+
15
+ return acc;
16
+ }, [])
17
+ .map(tag => ({
18
+ ...tag,
19
+ label: `${tag.quantity} ${tag.label}`,
20
+ }));
21
+ };
@@ -0,0 +1,21 @@
1
+ module.exports = () =>
2
+ function getNotesToModifierTags({ notes, modifierTags }) {
3
+ let noteTags = [];
4
+ if (notes && notes.length > 0) {
5
+ noteTags =
6
+ notes
7
+ .filter(Boolean)
8
+ .filter(item => item && !item.url)
9
+ .map((note, index) => {
10
+ const { message } = note;
11
+ return {
12
+ label: message,
13
+ value: index.toString(),
14
+ data: note,
15
+ quantity: 1,
16
+ };
17
+ }) || [];
18
+ }
19
+
20
+ return modifierTags.concat(noteTags);
21
+ };