@darkpos/pricing 1.0.48 → 1.0.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.
@@ -0,0 +1,27 @@
1
+ const usePricing = require('../index');
2
+
3
+ const pricingService = usePricing();
4
+
5
+ describe('Modifier actions', () => {
6
+ test('CU-86dv8hzxg modifier.isGroup fn', () => {
7
+ expect(
8
+ pricingService.modifier.isGroup({
9
+ attributes: ['group'],
10
+ })
11
+ ).toBe(true);
12
+
13
+ expect(
14
+ pricingService.modifier.isGroup({
15
+ properties: {
16
+ group: {},
17
+ },
18
+ })
19
+ ).toBe(false);
20
+ expect(
21
+ pricingService.modifier.isGroup({
22
+ atrributes: [],
23
+ properties: {},
24
+ })
25
+ ).toBe(false);
26
+ });
27
+ });
@@ -11,7 +11,7 @@ module.exports = ({ modifierActions, _, settings }) =>
11
11
  !modifierActions.isAmountOverride(each) &&
12
12
  !modifierActions.isDepartment(each) &&
13
13
  modifierActions.isDirect(each) &&
14
- !modifierActions.isGroupOfModifiers(each)
14
+ !modifierActions.isGroup(each)
15
15
  )
16
16
  .map(modifier => {
17
17
  const { name, _id, compute = {} } = modifier;
@@ -148,6 +148,7 @@ const isCalculatedPaymentModifier = require('./isCalculatedPaymentModifier');
148
148
  const isChild = require('./isChild');
149
149
  const isExtractCalculatedValue = require('./isExtractCalculatedValue');
150
150
  const getPriceWithoutModifier = require('./getPriceWithoutModifier');
151
+ const isGroup = require('./isGroup');
151
152
 
152
153
  const modifierActions = (deps = {}) => {
153
154
  const actions = {};
@@ -309,6 +310,7 @@ const modifierActions = (deps = {}) => {
309
310
  isChild: isChild(innerDeps),
310
311
  isExtractCalculatedValue: isExtractCalculatedValue(innerDeps),
311
312
  getPriceWithoutModifier: getPriceWithoutModifier(innerDeps),
313
+ isGroup: isGroup(innerDeps),
312
314
  });
313
315
 
314
316
  Object.keys(freezedActions).forEach(actionName => {
@@ -0,0 +1,10 @@
1
+ module.exports = ({ actions }) =>
2
+ function isGroup(modifier) {
3
+ if (!modifier) return false;
4
+ return !!(
5
+ actions.hasAttribute(modifier, 'group') ||
6
+ (modifier.properties &&
7
+ modifier.properties.group &&
8
+ Object.keys(modifier.properties.group) > 0)
9
+ );
10
+ };
@@ -14,7 +14,7 @@ module.exports = ({ actions, settings, _ }) => {
14
14
  const updatedQuantity = reset
15
15
  ? quantity
16
16
  : parseInt(`${item.quantity}${quantity}`, 10);
17
- const { updatedOrder } = actions.updateItem({
17
+ return actions.updateItem({
18
18
  order,
19
19
  itemIndex,
20
20
  item: {
@@ -22,16 +22,18 @@ module.exports = ({ actions, settings, _ }) => {
22
22
  quantity: updatedQuantity,
23
23
  },
24
24
  });
25
- return updatedOrder;
26
25
  }
27
26
  if (isBefore) {
28
- return actions.addItem({
27
+ const result = actions.addItem({
29
28
  order,
30
29
  item: { isPending: true },
31
30
  cache,
32
31
  overridenQuantity: quantity,
33
32
  });
33
+
34
+ if (result && result.updatedOrder) return result.updatedOrder;
34
35
  }
36
+
35
37
  return order;
36
38
  };
37
39
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.48",
3
+ "version": "1.0.50",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -40,5 +40,5 @@
40
40
  "supertest": "^6.2.3",
41
41
  "supervisor": "^0.12.0"
42
42
  },
43
- "gitHead": "4706909fded1e1083441ae48c8dc154cd569a48b"
43
+ "gitHead": "fc073d4d5ff5b5473b177e9462584caed71f3867"
44
44
  }