@darkpos/pricing 1.0.88 → 1.0.90
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,107 @@
|
|
|
1
|
+
const orders = [
|
|
2
|
+
{
|
|
3
|
+
end: {
|
|
4
|
+
requestDate: '2025-05-07T20:28:00Z',
|
|
5
|
+
actualDate: '',
|
|
6
|
+
location: {
|
|
7
|
+
name: 'PPSOL',
|
|
8
|
+
locationType: 'store',
|
|
9
|
+
storeId: '67b78ebcb1f0420011470f2b',
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
properties: {
|
|
13
|
+
pieceCount: '',
|
|
14
|
+
pieces: [
|
|
15
|
+
{
|
|
16
|
+
departmentId: '67fea241af24e570c032b33f',
|
|
17
|
+
name: 'Dry Cleaning',
|
|
18
|
+
code: 'D',
|
|
19
|
+
tagSize: 'small',
|
|
20
|
+
count: '',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
departmentId: '67fea241af24e570c032b340',
|
|
24
|
+
name: 'Laundry',
|
|
25
|
+
code: 'L',
|
|
26
|
+
tagSize: 'small',
|
|
27
|
+
count: '',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
notify: {},
|
|
31
|
+
print: ['quick-order-receipt'],
|
|
32
|
+
},
|
|
33
|
+
customer: {
|
|
34
|
+
_id: '67f6dedcf5384804f5a42e43',
|
|
35
|
+
},
|
|
36
|
+
status: {
|
|
37
|
+
order: 'open',
|
|
38
|
+
detailed: false,
|
|
39
|
+
},
|
|
40
|
+
subTotal: 0,
|
|
41
|
+
subTotals: {},
|
|
42
|
+
total: 0,
|
|
43
|
+
tax: 0,
|
|
44
|
+
start: {
|
|
45
|
+
requestDate: '2025-05-07T19:28',
|
|
46
|
+
actualDate: '2025-05-07T19:28',
|
|
47
|
+
location: {
|
|
48
|
+
name: 'PPSOL',
|
|
49
|
+
locationType: 'store',
|
|
50
|
+
storeId: '67b78ebcb1f0420011470f2b',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
end: {
|
|
56
|
+
requestDate: '2025-05-07T20:30:00Z',
|
|
57
|
+
actualDate: '',
|
|
58
|
+
location: {
|
|
59
|
+
name: 'Sunshine Cleaners',
|
|
60
|
+
locationType: 'store',
|
|
61
|
+
storeId: '67e1c09c05b96100127280a8',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
properties: {
|
|
65
|
+
pieceCount: '10',
|
|
66
|
+
pieces: [
|
|
67
|
+
{
|
|
68
|
+
departmentId: '67fea241af24e570c032b33f',
|
|
69
|
+
name: 'Dry Cleaning',
|
|
70
|
+
code: 'D',
|
|
71
|
+
tagSize: 'small',
|
|
72
|
+
count: '5',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
departmentId: '67fea241af24e570c032b340',
|
|
76
|
+
name: 'Laundry',
|
|
77
|
+
code: 'L',
|
|
78
|
+
tagSize: 'small',
|
|
79
|
+
count: '5',
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
notify: {},
|
|
83
|
+
print: ['quick-order-receipt'],
|
|
84
|
+
},
|
|
85
|
+
customer: {
|
|
86
|
+
_id: '67edaa1721d00ec86d54071e',
|
|
87
|
+
},
|
|
88
|
+
status: {
|
|
89
|
+
order: 'open',
|
|
90
|
+
detailed: false,
|
|
91
|
+
},
|
|
92
|
+
subTotal: 0,
|
|
93
|
+
subTotals: {},
|
|
94
|
+
total: 0,
|
|
95
|
+
tax: 0,
|
|
96
|
+
start: {
|
|
97
|
+
requestDate: '2025-05-07T19:30',
|
|
98
|
+
actualDate: '2025-05-07T19:30',
|
|
99
|
+
location: {
|
|
100
|
+
name: 'Sunshine Cleaners',
|
|
101
|
+
locationType: 'store',
|
|
102
|
+
storeId: '67e1c09c05b96100127280a8',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
module.exports = orders;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const utils = require('@darkpos/utils');
|
|
2
|
+
const usePricing = require('../../index');
|
|
3
|
+
const mockStores = require('../mocks/stores');
|
|
4
|
+
const orders = require('../mocks/setPieces/ordersMock');
|
|
5
|
+
|
|
6
|
+
const session = {
|
|
7
|
+
store: mockStores[0],
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const pricingService = usePricing(session);
|
|
11
|
+
|
|
12
|
+
describe('set pieces', () => {
|
|
13
|
+
test('Normalize pieces that are not numbers', () => {
|
|
14
|
+
const order = orders[0];
|
|
15
|
+
|
|
16
|
+
const newOrder = pricingService.order.setPieces({ order });
|
|
17
|
+
expect(newOrder.properties.pieceCount).toBe(0);
|
|
18
|
+
newOrder.properties.pieces.map(item => expect(item.count).toBe(0));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('Normalize pieces that are strings into numbers', () => {
|
|
22
|
+
const order = orders[1];
|
|
23
|
+
|
|
24
|
+
const newOrder = pricingService.order.setPieces({ order });
|
|
25
|
+
expect(newOrder.properties.pieceCount).toBe(10);
|
|
26
|
+
expect(typeof newOrder.properties.pieceCount).toBe('number');
|
|
27
|
+
newOrder.properties.pieces.map(item => {
|
|
28
|
+
expect(item.count).toBe(5);
|
|
29
|
+
expect(typeof item.count).toBe('number');
|
|
30
|
+
return {};
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
test('utils helpers to toNumberOrZero', () => {
|
|
34
|
+
const number1 = 0;
|
|
35
|
+
const number2 = '';
|
|
36
|
+
const number3 = NaN;
|
|
37
|
+
const number4 = 'abc';
|
|
38
|
+
const number5 = 10;
|
|
39
|
+
|
|
40
|
+
const value1 = utils.helpers.toNumberOrZero(number1);
|
|
41
|
+
const value2 = utils.helpers.toNumberOrZero(number2);
|
|
42
|
+
const value3 = utils.helpers.toNumberOrZero(number3);
|
|
43
|
+
const value4 = utils.helpers.toNumberOrZero(number4);
|
|
44
|
+
const value5 = utils.helpers.toNumberOrZero(number5);
|
|
45
|
+
expect(value1).toBe(0);
|
|
46
|
+
expect(value2).toBe(0);
|
|
47
|
+
expect(value3).toBe(0);
|
|
48
|
+
expect(value4).toBe(0);
|
|
49
|
+
expect(value5).toBe(10);
|
|
50
|
+
});
|
|
51
|
+
});
|
package/lib/order/index.js
CHANGED
|
@@ -93,6 +93,7 @@ const getNewItems = require('./getNewItems');
|
|
|
93
93
|
const mapSubOrders = require('./mapSubOrders');
|
|
94
94
|
const isFullyPaid = require('./isFullyPaid');
|
|
95
95
|
const getUpdatedStatus = require('./getUpdatedStatus');
|
|
96
|
+
const setPieces = require('./setPieces');
|
|
96
97
|
|
|
97
98
|
const orderActions = (deps = {}) => {
|
|
98
99
|
const actions = {};
|
|
@@ -197,6 +198,7 @@ const orderActions = (deps = {}) => {
|
|
|
197
198
|
mapSubOrders: mapSubOrders(innerDeps),
|
|
198
199
|
isFullyPaid: isFullyPaid(innerDeps),
|
|
199
200
|
getUpdatedStatus: getUpdatedStatus(innerDeps),
|
|
201
|
+
setPieces: setPieces(innerDeps),
|
|
200
202
|
});
|
|
201
203
|
|
|
202
204
|
Object.keys(freezedActions).forEach(actionName => {
|
package/lib/order/isDetailed.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
module.exports = () =>
|
|
2
2
|
function isDetailed(order) {
|
|
3
|
-
return !!(
|
|
3
|
+
return !!(
|
|
4
|
+
order &&
|
|
5
|
+
((Array.isArray(order.items) && order.items.length) ||
|
|
6
|
+
(Array.isArray(order.orders) &&
|
|
7
|
+
order.orders.length &&
|
|
8
|
+
order.orders.some(
|
|
9
|
+
subOrder => Array.isArray(subOrder.items) && subOrder.items.length
|
|
10
|
+
)))
|
|
11
|
+
);
|
|
4
12
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module.exports = ({ utils }) => {
|
|
2
|
+
const { helpers } = utils;
|
|
3
|
+
return function setPieces({ order }) {
|
|
4
|
+
const nextOrder = {
|
|
5
|
+
...order,
|
|
6
|
+
properties: {
|
|
7
|
+
...(order.properties || {}),
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
nextOrder.properties.pieceCount = helpers.toNumberOrZero(
|
|
12
|
+
nextOrder.properties.pieceCount
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
if (Array.isArray(nextOrder.properties.pieces)) {
|
|
16
|
+
nextOrder.properties.pieces = nextOrder.properties.pieces.map(pc => ({
|
|
17
|
+
...pc,
|
|
18
|
+
count: helpers.toNumberOrZero(pc.count),
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return nextOrder;
|
|
23
|
+
};
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.90",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@darkpos/utils": "^1.0.
|
|
36
|
+
"@darkpos/utils": "^1.0.13",
|
|
37
37
|
"crypto-js": "^4.2.0",
|
|
38
38
|
"lodash": "^4.17.21",
|
|
39
39
|
"moment-timezone": "^0.5.34"
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"supertest": "^6.2.3",
|
|
52
52
|
"supervisor": "^0.12.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "9c351c72bca0563fb454c0cb51d50dcaf49ba37d"
|
|
55
55
|
}
|