@darkpos/pricing 1.0.132 → 1.0.133

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.
@@ -253,7 +253,11 @@ describe('addItem function', () => {
253
253
  });
254
254
  expect(updatedOrder2.items[1]).toMatchObject({
255
255
  name: 'the parent item',
256
- modifiers: [],
256
+ modifiers: [
257
+ {
258
+ name: 'General Repair Department',
259
+ },
260
+ ],
257
261
  });
258
262
 
259
263
  const relatedItem2 = {
@@ -291,7 +295,11 @@ describe('addItem function', () => {
291
295
  });
292
296
  expect(updatedOrder3.items[2]).toMatchObject({
293
297
  name: 'the parent item',
294
- modifiers: [],
298
+ modifiers: [
299
+ {
300
+ name: 'General Repair Department',
301
+ },
302
+ ],
295
303
  });
296
304
  });
297
305
  });
@@ -0,0 +1,11 @@
1
+ module.exports = () =>
2
+ function getAddModifiers(item) {
3
+ if (
4
+ !item ||
5
+ !item.properties ||
6
+ !Array.isArray(item.properties.addModifiers)
7
+ )
8
+ return [];
9
+
10
+ return item.properties.addModifiers;
11
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = () =>
2
+ function hasAddModifiers(item) {
3
+ return (
4
+ !!item &&
5
+ !!item.properties &&
6
+ !!item.properties.addModifiers &&
7
+ !!item.properties.addModifiers.length
8
+ );
9
+ };
package/lib/item/index.js CHANGED
@@ -75,6 +75,8 @@ const getSerialStatus = require('./getSerialStatus');
75
75
  const removeDepartmentModifiers = require('./removeDepartmentModifiers');
76
76
  const isRemoveParentItem = require('./isRemoveParentItem');
77
77
  const hasRelatedItems = require('./hasRelatedItems');
78
+ const getAddModifiers = require('./getAddModifiers');
79
+ const hasAddModifiers = require('./hasAddModifiers');
78
80
 
79
81
  const itemActions = (deps = {}) => {
80
82
  const actions = {};
@@ -163,6 +165,8 @@ const itemActions = (deps = {}) => {
163
165
  removeDepartmentModifiers: removeDepartmentModifiers(innerDeps),
164
166
  isRemoveParentItem: isRemoveParentItem(innerDeps),
165
167
  hasRelatedItems: hasRelatedItems(innerDeps),
168
+ getAddModifiers: getAddModifiers(innerDeps),
169
+ hasAddModifiers: hasAddModifiers(innerDeps),
166
170
  });
167
171
 
168
172
  Object.keys(freezedActions).forEach(actionName => {
@@ -265,6 +265,11 @@ module.exports = ({ actions, itemActions, modifierActions, settings, _ }) => {
265
265
  nextOrder.items.splice(idxToRemove, 1);
266
266
  }
267
267
 
268
+ nextOrder = actions.addModifiersToParentItem({
269
+ order: nextOrder,
270
+ relatedItem: orderItem,
271
+ });
272
+
268
273
  return {
269
274
  updatedOrder: nextOrder,
270
275
  itemIndex: nextItemIndex,
@@ -0,0 +1,41 @@
1
+ module.exports = ({ actions, itemActions }) =>
2
+ function addModifiersToParentItem({ order, relatedItem }) {
3
+ if (
4
+ !order ||
5
+ !itemActions.isRelatedItem(relatedItem) ||
6
+ !itemActions.hasAddModifiers(relatedItem) ||
7
+ itemActions.isRepairOnly(relatedItem)
8
+ ) {
9
+ return order;
10
+ }
11
+
12
+ let nextOrder = { ...order };
13
+
14
+ const parentItem = itemActions.getParentItem(nextOrder.items, relatedItem);
15
+ const parentIndex = actions.getItemIndex({
16
+ order: nextOrder,
17
+ item: parentItem,
18
+ });
19
+
20
+ if (parentIndex < 0) return nextOrder;
21
+
22
+ const relatedModifiersToAdd = itemActions
23
+ .getAddModifiers(relatedItem)
24
+ .filter(
25
+ mod =>
26
+ !parentItem.modifiers.some(itemMod => itemMod.modifierId === mod._id)
27
+ );
28
+
29
+ nextOrder = relatedModifiersToAdd.reduce(
30
+ (acc, modifier) =>
31
+ actions.addItemModifier({
32
+ itemIndex: parentIndex,
33
+ order: acc,
34
+ modifier,
35
+ originalItem: parentItem,
36
+ }),
37
+ nextOrder
38
+ );
39
+
40
+ return nextOrder;
41
+ };
@@ -94,6 +94,7 @@ const getUpdatedStatus = require('./getUpdatedStatus');
94
94
  const setPieces = require('./setPieces');
95
95
  const copyItemToParents = require('./copyItemToParents');
96
96
  const getItemsWithParents = require('./getItemsWithParents');
97
+ const addModifiersToParentItem = require('./addModifiersToParentItem');
97
98
 
98
99
  const orderActions = (deps = {}) => {
99
100
  const actions = {};
@@ -199,6 +200,7 @@ const orderActions = (deps = {}) => {
199
200
  setPieces: setPieces(innerDeps),
200
201
  copyItemToParents: copyItemToParents(innerDeps),
201
202
  getItemsWithParents: getItemsWithParents(innerDeps),
203
+ addModifiersToParentItem: addModifiersToParentItem(innerDeps),
202
204
  });
203
205
 
204
206
  Object.keys(freezedActions).forEach(actionName => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.132",
3
+ "version": "1.0.133",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -52,5 +52,5 @@
52
52
  "supertest": "^6.2.3",
53
53
  "supervisor": "^0.12.0"
54
54
  },
55
- "gitHead": "aa74813e6d89c8f6befeebeb07ebaaefef8e5d31"
55
+ "gitHead": "1cec04f4a6fc32238922712068994984b62ab92d"
56
56
  }