@darkpos/pricing 1.0.84 → 1.0.85

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.
@@ -1855,4 +1855,74 @@ describe('Modifier actions', () => {
1855
1855
 
1856
1856
  expect(updatedOrder2.items[0].modifiers.length).toEqual(1);
1857
1857
  });
1858
+
1859
+ test('Should not add modifiers if tags do not match', () => {
1860
+ const order = {
1861
+ id: 'ord-123',
1862
+ items: [],
1863
+ modifiers: [],
1864
+ };
1865
+ const modifier = {
1866
+ _id: 1,
1867
+ compute: {
1868
+ amount: 10,
1869
+ action: 'subtract',
1870
+ type: 'fixed',
1871
+ },
1872
+ tags: ['tagA', 'tagB'],
1873
+ };
1874
+ order.items.push({
1875
+ quantity: 2,
1876
+ itemId: '123',
1877
+ price: 100,
1878
+ modifiers: [],
1879
+ tags: ['otherTag'],
1880
+ });
1881
+
1882
+ const updatedOrder = pricingService.order.addItemModifier({
1883
+ order,
1884
+ modifier,
1885
+ itemIndex: 0,
1886
+ });
1887
+
1888
+ expect(updatedOrder.items[0].modifiers.length).toEqual(0);
1889
+ });
1890
+
1891
+ test('Should add modifier if tags match', () => {
1892
+ const order = {
1893
+ id: 'ord-123',
1894
+ items: [],
1895
+ modifiers: [],
1896
+ };
1897
+ const modifier = {
1898
+ _id: 1,
1899
+ compute: {
1900
+ amount: 10,
1901
+ action: 'subtract',
1902
+ type: 'fixed',
1903
+ },
1904
+ tags: ['tagA', 'tagB'],
1905
+ };
1906
+ order.items.push({
1907
+ quantity: 2,
1908
+ itemId: '123',
1909
+ price: 100,
1910
+ modifiers: [],
1911
+ tags: ['tagA'],
1912
+ });
1913
+
1914
+ let error = '';
1915
+ const updatedOrder = pricingService.order.addItemModifier({
1916
+ order,
1917
+ modifier,
1918
+ itemIndex: 0,
1919
+ onError: err => {
1920
+ error = err;
1921
+ },
1922
+ });
1923
+
1924
+ expect(error).toEqual('');
1925
+
1926
+ expect(updatedOrder.items[0].modifiers.length).toEqual(1);
1927
+ });
1858
1928
  });
package/lib/item/index.js CHANGED
@@ -59,6 +59,7 @@ const adjustFixedModifiersDifference = require('./adjustFixedModifiersDifference
59
59
  const validateCreditModifiersTotal = require('./validateCreditModifiersTotal');
60
60
  const adjustCreditModifiersDifference = require('./adjustCreditModifiersDifference');
61
61
  const getSubtotal = require('./getSubtotal');
62
+ const isSomeTagsMatch = require('./isSomeTagsMatch');
62
63
  const getTotals = require('./getTotals');
63
64
  const patchItem = require('./patchItem');
64
65
 
@@ -133,6 +134,7 @@ const itemActions = (deps = {}) => {
133
134
  validateCreditModifiersTotal: validateCreditModifiersTotal(innerDeps),
134
135
  adjustCreditModifiersDifference: adjustCreditModifiersDifference(innerDeps),
135
136
  getSubtotal: getSubtotal(innerDeps),
137
+ isSomeTagsMatch: isSomeTagsMatch(innerDeps),
136
138
  getTotals: getTotals(innerDeps),
137
139
  patchItem: patchItem(innerDeps),
138
140
  });
@@ -0,0 +1,13 @@
1
+ module.exports = () =>
2
+ function isSomeTagsMatch({ item, tags }) {
3
+ if (
4
+ !item ||
5
+ !Array.isArray(item.tags) ||
6
+ item.tags.length === 0 ||
7
+ !Array.isArray(tags) ||
8
+ tags.length === 0
9
+ )
10
+ return true;
11
+
12
+ return item.tags.some(tag => tags.includes(tag));
13
+ };
@@ -180,6 +180,11 @@ module.exports = ({ actions, itemActions, modifierActions, utils, _ }) => {
180
180
  if (!order || itemIndex < 0 || !modifier) return order;
181
181
 
182
182
  let item = actions.getSelectedItem({ order, itemIndex });
183
+
184
+ if (!itemActions.isSomeTagsMatch({ item, tags: modifier.tags })) {
185
+ return order;
186
+ }
187
+
183
188
  const customer = actions.getCustomer(order);
184
189
  const contains =
185
190
  !_.isEmpty(item.modifiers) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.84",
3
+ "version": "1.0.85",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -51,5 +51,5 @@
51
51
  "supertest": "^6.2.3",
52
52
  "supervisor": "^0.12.0"
53
53
  },
54
- "gitHead": "d15a98cdefcf27cdaf41a8096a6c6c7dcdfcc13f"
54
+ "gitHead": "275e9dcadc8bca5f47d4c444685c154f998d2862"
55
55
  }