@darkpos/pricing 1.0.66 → 1.0.68
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.
- package/__TEST__/item/getModifierTags.test.js +4 -3
- package/__TEST__/item.test.js +450 -1
- package/__TEST__/modifier/getInvalidRequiredModifiers.test.js +3877 -0
- package/__TEST__/modifier/hasModifier.test.js +72 -1
- package/__TEST__/order/addItem.test.js +103 -0
- package/lib/item/getAddModifiers.js +11 -0
- package/lib/item/getInvalidRequiredModifiers.js +12 -3
- package/lib/item/getModifierTags.js +2 -12
- package/lib/item/getRelatedItems.js +12 -0
- package/lib/item/hasAddModifiers.js +9 -0
- package/lib/item/hasModifier.js +23 -12
- package/lib/item/hasModifiers.js +2 -2
- package/lib/item/index.js +6 -2
- package/lib/item/removeModifier.js +42 -17
- package/lib/item/removeModifiers.js +2 -1
- package/lib/modifier/hasAddModifier.js +7 -0
- package/lib/modifier/index.js +2 -0
- package/lib/order/addItem.js +28 -1
- package/lib/order/getModifierRelations.js +7 -0
- package/lib/order/getRelatedItems.js +1 -0
- package/lib/order/index.js +2 -4
- package/lib/order/removeItem.js +79 -38
- package/lib/order/removeModifier.js +1 -0
- package/package.json +4 -2
- package/lib/item/removePaymentModifiers.js +0 -15
- package/lib/order/addDiscountModifier.js +0 -9
- package/lib/order/removeDiscountModifier.js +0 -16
package/lib/order/removeItem.js
CHANGED
|
@@ -1,53 +1,94 @@
|
|
|
1
|
-
module.exports = ({ actions,
|
|
2
|
-
const
|
|
3
|
-
items.map(each => {
|
|
4
|
-
const item = { ...each };
|
|
5
|
-
if (item.properties && item.properties.parentId === parentId)
|
|
6
|
-
item.properties.includeParent = false;
|
|
7
|
-
return item;
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
return function removeItem({ order, item, checkQuantity, hard = true }) {
|
|
11
|
-
if (!item) return order;
|
|
12
|
-
|
|
1
|
+
module.exports = ({ actions, itemActions }) => {
|
|
2
|
+
const remove = ({ order, item, checkQuantity }) => {
|
|
13
3
|
const orderItemIdx = actions.getItemIndex({ order, item });
|
|
14
4
|
if (orderItemIdx < 0) return order;
|
|
15
5
|
|
|
16
|
-
|
|
17
|
-
const orderItem = items[orderItemIdx];
|
|
18
|
-
const relatedItems = actions.getRelatedItems({ order, item });
|
|
19
|
-
const hasRelatedItem = !_.isEmpty(relatedItems);
|
|
6
|
+
const items = [...order.items];
|
|
20
7
|
|
|
21
|
-
if (
|
|
22
|
-
items[orderItemIdx] = { ...orderItem, price: 0, modifiers: [] };
|
|
23
|
-
if (hasRelatedItem) {
|
|
24
|
-
items = updateRelatedItems(items, item._id);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
// Decrease the quantity
|
|
28
|
-
else if (
|
|
8
|
+
if (
|
|
29
9
|
checkQuantity &&
|
|
30
10
|
items[orderItemIdx] &&
|
|
31
11
|
items[orderItemIdx].quantity > 1
|
|
32
|
-
)
|
|
33
|
-
items[orderItemIdx] = { ...orderItem, quantity: orderItem.quantity - 1 };
|
|
34
|
-
// Remove
|
|
35
|
-
else items.splice(orderItemIdx, 1);
|
|
36
|
-
|
|
37
|
-
// if it is the last relatedItem
|
|
38
|
-
if (
|
|
39
|
-
itemActions.isRelatedItem(item) &&
|
|
40
|
-
!itemActions.isParentIncluded(item)
|
|
41
12
|
) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
13
|
+
items[orderItemIdx] = { ...item, quantity: item.quantity - 1 };
|
|
14
|
+
return {
|
|
15
|
+
...order,
|
|
16
|
+
items,
|
|
17
|
+
};
|
|
46
18
|
}
|
|
47
19
|
|
|
48
|
-
|
|
20
|
+
items.splice(orderItemIdx, 1);
|
|
21
|
+
|
|
22
|
+
let resultedOrder = {
|
|
49
23
|
...order,
|
|
50
24
|
items,
|
|
51
25
|
};
|
|
26
|
+
|
|
27
|
+
if (itemActions.isRelatedItem(item) && itemActions.hasAddModifiers(item)) {
|
|
28
|
+
const parentItem = itemActions.getParentItem(order.items, item);
|
|
29
|
+
|
|
30
|
+
if (parentItem) {
|
|
31
|
+
resultedOrder = item.properties.addModifiers.reduce(
|
|
32
|
+
(prevOrder, addModifier) => {
|
|
33
|
+
if (
|
|
34
|
+
!itemActions.hasModifier({
|
|
35
|
+
item: parentItem,
|
|
36
|
+
modifier: addModifier,
|
|
37
|
+
relatedItems: actions.getRelatedItems({
|
|
38
|
+
order: prevOrder,
|
|
39
|
+
item: parentItem,
|
|
40
|
+
}),
|
|
41
|
+
originalModifier: addModifier,
|
|
42
|
+
})
|
|
43
|
+
) {
|
|
44
|
+
const updatedItem = itemActions.removeModifier({
|
|
45
|
+
item: parentItem,
|
|
46
|
+
modifier: addModifier,
|
|
47
|
+
originalItem: parentItem,
|
|
48
|
+
});
|
|
49
|
+
const itemIndexToUpdate = actions.getItemIndex({
|
|
50
|
+
order: prevOrder,
|
|
51
|
+
item: parentItem,
|
|
52
|
+
});
|
|
53
|
+
if (itemIndexToUpdate >= 0) {
|
|
54
|
+
const itemsToUpdate = [...prevOrder.items];
|
|
55
|
+
|
|
56
|
+
itemsToUpdate.splice(itemIndexToUpdate, 1, updatedItem);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...resultedOrder,
|
|
60
|
+
items: itemsToUpdate,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return resultedOrder;
|
|
65
|
+
},
|
|
66
|
+
resultedOrder
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const relatedItems = actions.getRelatedItems({ order, item });
|
|
72
|
+
if (relatedItems.length > 0) {
|
|
73
|
+
return relatedItems.reduce(
|
|
74
|
+
(prevOrder, relatedItem) =>
|
|
75
|
+
remove({
|
|
76
|
+
order: prevOrder,
|
|
77
|
+
item: relatedItem,
|
|
78
|
+
checkQuantity,
|
|
79
|
+
}),
|
|
80
|
+
resultedOrder
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return resultedOrder;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return function removeItem({ order, item, checkQuantity }) {
|
|
88
|
+
if (!order || !Array.isArray(order.items) || !item) return order;
|
|
89
|
+
|
|
90
|
+
const nextOrder = remove({ order, item, checkQuantity });
|
|
91
|
+
|
|
92
|
+
return nextOrder;
|
|
52
93
|
};
|
|
53
94
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.68",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
"test:split": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/split.test.js",
|
|
21
21
|
"test:getModifierTags": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/item/getModifierTags.test.js",
|
|
22
22
|
"test:createIndirectModifier": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/modifier/createIndirectModifier.test.js",
|
|
23
|
+
"test:getInvalidRequiredModifiers": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/modifier/getInvalidRequiredModifiers",
|
|
23
24
|
"test:conditionsNotMet": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/conditionsNotMet.test.js",
|
|
24
25
|
"test:pickEndDate": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/pickEndDate.test.js",
|
|
25
26
|
"test:modifier": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/modifier.test.js",
|
|
26
27
|
"test:paymentModifiers": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/order-payment-modifier.test.js",
|
|
28
|
+
"test:addItem": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/addItem.test.js",
|
|
27
29
|
"lint": "eslint --quiet lib/"
|
|
28
30
|
},
|
|
29
31
|
"publishConfig": {
|
|
@@ -47,5 +49,5 @@
|
|
|
47
49
|
"supertest": "^6.2.3",
|
|
48
50
|
"supervisor": "^0.12.0"
|
|
49
51
|
},
|
|
50
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "ac976fa76195b19e32645c5defe5df41c867609c"
|
|
51
53
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module.exports = ({ actions, modifierActions }) =>
|
|
2
|
-
function removePaymentModifiers({ items }) {
|
|
3
|
-
const paymentModifiers = items.modifiers.filter(mod =>
|
|
4
|
-
modifierActions.isPaymentModifier(mod)
|
|
5
|
-
);
|
|
6
|
-
|
|
7
|
-
return paymentModifiers.map(paymentMod =>
|
|
8
|
-
items.map(item =>
|
|
9
|
-
actions.removeModifier({
|
|
10
|
-
item,
|
|
11
|
-
modifier: paymentMod,
|
|
12
|
-
})
|
|
13
|
-
)
|
|
14
|
-
);
|
|
15
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
module.exports = ({ actions }) =>
|
|
2
|
-
function addDiscountModifier({ order, modifier }) {
|
|
3
|
-
if (!order || !modifier) return order;
|
|
4
|
-
const clearedOrder = actions.removeDiscountModifier(order);
|
|
5
|
-
return actions.addModifier({
|
|
6
|
-
order: clearedOrder,
|
|
7
|
-
modifier,
|
|
8
|
-
});
|
|
9
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
module.exports = ({ modifierActions, itemActions }) =>
|
|
2
|
-
function removeDiscountModifiers(order) {
|
|
3
|
-
if (!order || !Array.isArray(order.modifiers)) return order;
|
|
4
|
-
const nextOrder = { ...order };
|
|
5
|
-
let { modifiers, items } = nextOrder;
|
|
6
|
-
const discountModifiers = modifiers.filter(modifierActions.isDiscount);
|
|
7
|
-
modifiers = modifiers.filter(each => !modifierActions.isDiscount(each));
|
|
8
|
-
if (items)
|
|
9
|
-
items = items.map(each =>
|
|
10
|
-
itemActions.removeModifiers({
|
|
11
|
-
item: each,
|
|
12
|
-
modifiers: discountModifiers,
|
|
13
|
-
})
|
|
14
|
-
);
|
|
15
|
-
return { ...order, modifiers, items };
|
|
16
|
-
};
|