@darkpos/pricing 1.0.102 → 1.0.103
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.
|
@@ -676,7 +676,7 @@ describe('Modifier actions', () => {
|
|
|
676
676
|
properties: {
|
|
677
677
|
isManual: true,
|
|
678
678
|
},
|
|
679
|
-
_id: '
|
|
679
|
+
_id: '5d97805a91c31603f8fc6ab0',
|
|
680
680
|
}),
|
|
681
681
|
expect.objectContaining({
|
|
682
682
|
name: 'Blue Label',
|
|
@@ -685,7 +685,7 @@ describe('Modifier actions', () => {
|
|
|
685
685
|
properties: {
|
|
686
686
|
isManual: true,
|
|
687
687
|
},
|
|
688
|
-
_id: '
|
|
688
|
+
_id: '49327d26c324cb709456a279',
|
|
689
689
|
}),
|
|
690
690
|
])
|
|
691
691
|
);
|
|
@@ -739,21 +739,21 @@ describe('Modifier actions', () => {
|
|
|
739
739
|
expect(result).toStrictEqual([
|
|
740
740
|
{
|
|
741
741
|
name: 'Red Tag',
|
|
742
|
-
_id: '
|
|
742
|
+
_id: '5d97805a91c31603f8fc6ab0',
|
|
743
743
|
direct: true,
|
|
744
744
|
group: 'colorGroup1',
|
|
745
745
|
properties: { isManual: true, spreadFrom: 'abc123' },
|
|
746
746
|
},
|
|
747
747
|
{
|
|
748
748
|
name: 'White Shirt',
|
|
749
|
-
_id: '
|
|
749
|
+
_id: '3b115e8ff1d00d9ae4ea3601',
|
|
750
750
|
direct: true,
|
|
751
751
|
group: 'colorGroup1',
|
|
752
752
|
properties: { isManual: true, spreadFrom: 'abc123' },
|
|
753
753
|
},
|
|
754
754
|
{
|
|
755
755
|
name: 'Blue Label',
|
|
756
|
-
_id: '
|
|
756
|
+
_id: '49327d26c324cb709456a279',
|
|
757
757
|
direct: true,
|
|
758
758
|
group: 'colorGroup1',
|
|
759
759
|
properties: { isManual: true, spreadFrom: 'abc123' },
|
|
@@ -815,21 +815,21 @@ describe('Modifier actions', () => {
|
|
|
815
815
|
expect(result).toStrictEqual([
|
|
816
816
|
{
|
|
817
817
|
name: 'Red Tag',
|
|
818
|
-
_id: '
|
|
818
|
+
_id: '5d97805a91c31603f8fc6ab0',
|
|
819
819
|
direct: true,
|
|
820
820
|
group: 'colorGroup1',
|
|
821
821
|
properties: { isManual: true, spreadFrom: 'abc123' },
|
|
822
822
|
},
|
|
823
823
|
{
|
|
824
824
|
name: 'White Shirt',
|
|
825
|
-
_id: '
|
|
825
|
+
_id: '3b115e8ff1d00d9ae4ea3601',
|
|
826
826
|
direct: true,
|
|
827
827
|
group: 'colorGroup1',
|
|
828
828
|
properties: { isManual: true, spreadFrom: 'abc123' },
|
|
829
829
|
},
|
|
830
830
|
{
|
|
831
831
|
name: 'Blue Label',
|
|
832
|
-
_id: '
|
|
832
|
+
_id: '49327d26c324cb709456a279',
|
|
833
833
|
direct: true,
|
|
834
834
|
group: 'colorGroup1',
|
|
835
835
|
properties: { isManual: true, spreadFrom: 'abc123' },
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module.exports = ({ sha256 }) => {
|
|
2
|
+
function combineHashParts(partA, partB) {
|
|
3
|
+
let combined = '';
|
|
4
|
+
try {
|
|
5
|
+
combined = partA
|
|
6
|
+
.split('')
|
|
7
|
+
.map((char, index) => {
|
|
8
|
+
const digitA = parseInt(char, 16);
|
|
9
|
+
const digitB = parseInt(partB[index], 16);
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line no-bitwise
|
|
12
|
+
return (digitA ^ digitB).toString(16);
|
|
13
|
+
})
|
|
14
|
+
.join('')
|
|
15
|
+
.padStart(partA.length, '0');
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.log(JSON.stringify(err));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return combined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function generateManualModifierId(parentId, name) {
|
|
24
|
+
const input = `${parentId}-${name}`;
|
|
25
|
+
const hash = sha256(input).toString(); // 64 hex characters
|
|
26
|
+
|
|
27
|
+
const firstPart = hash.slice(0, 24);
|
|
28
|
+
const lastPart = hash.slice(-24);
|
|
29
|
+
|
|
30
|
+
return combineHashParts(firstPart, lastPart); // 24-char hex string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return function createManualModifier({ parentId, name, group }) {
|
|
34
|
+
const _id = generateManualModifierId(parentId, name);
|
|
35
|
+
|
|
36
|
+
const manualModifier = {
|
|
37
|
+
name,
|
|
38
|
+
_id,
|
|
39
|
+
direct: true,
|
|
40
|
+
group,
|
|
41
|
+
properties: {
|
|
42
|
+
isManual: true,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return manualModifier;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module.exports = ({
|
|
1
|
+
module.exports = ({ actions }) => {
|
|
2
2
|
const csvToArray = input =>
|
|
3
3
|
input
|
|
4
4
|
.split(',')
|
|
@@ -39,23 +39,13 @@ module.exports = ({ sha256 }) => {
|
|
|
39
39
|
).filter(modName => otherModifiers.every(mod => mod.name !== modName));
|
|
40
40
|
|
|
41
41
|
modifiers.push(
|
|
42
|
-
...manualModifiersNames.map(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const _id = hash.substring(0, 24);
|
|
46
|
-
|
|
47
|
-
const manualModifier = {
|
|
42
|
+
...manualModifiersNames.map(each =>
|
|
43
|
+
actions.createManualModifier({
|
|
44
|
+
parentId: modifier._id,
|
|
48
45
|
name: each,
|
|
49
|
-
_id,
|
|
50
|
-
direct: true,
|
|
51
46
|
group: modifier.group,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return manualModifier;
|
|
58
|
-
})
|
|
47
|
+
})
|
|
48
|
+
)
|
|
59
49
|
);
|
|
60
50
|
}
|
|
61
51
|
|
package/lib/modifier/index.js
CHANGED
|
@@ -166,6 +166,7 @@ const getOverrideNote = require('./getOverrideNote');
|
|
|
166
166
|
const isNotesOverride = require('./isNotesOverride');
|
|
167
167
|
const isOverrideSubtotal = require('./isOverrideSubtotal');
|
|
168
168
|
const validatePaymentCondition = require('./validatePaymentCondition');
|
|
169
|
+
const createManualModifier = require('./createManualModifier');
|
|
169
170
|
|
|
170
171
|
const modifierActions = (deps = {}) => {
|
|
171
172
|
const actions = {};
|
|
@@ -345,6 +346,7 @@ const modifierActions = (deps = {}) => {
|
|
|
345
346
|
isNotesOverride: isNotesOverride(innerDeps),
|
|
346
347
|
isOverrideSubtotal: isOverrideSubtotal(innerDeps),
|
|
347
348
|
validatePaymentCondition: validatePaymentCondition(innerDeps),
|
|
349
|
+
createManualModifier: createManualModifier(innerDeps),
|
|
348
350
|
});
|
|
349
351
|
|
|
350
352
|
Object.keys(freezedActions).forEach(actionName => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.103",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"supertest": "^6.2.3",
|
|
55
55
|
"supervisor": "^0.12.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "032bea629a5c32d78886daca4d2382b847b5d075"
|
|
58
58
|
}
|