@darkpos/pricing 1.0.131 → 1.0.133
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.test.js +2 -77
- package/__TEST__/modifier/getInvalidRequiredModifiers.test.js +1 -1
- package/__TEST__/modifier/hasModifier.test.js +114 -44
- package/__TEST__/order/addItem.test.js +2 -2
- package/__TEST__/order/order.test.js +75 -0
- package/__TEST__/order/split.test.js +14 -11
- package/lib/item/getSplitDepartment.js +2 -2
- package/lib/item/hasRelatedItems.js +10 -0
- package/lib/item/index.js +12 -6
- package/lib/item/isRemoveParentItem.js +4 -0
- package/lib/item/isRepairOnly.js +4 -0
- package/lib/item/removeDepartmentModifiers.js +19 -0
- package/lib/modifier/getInheritedModifiers.js +10 -26
- package/lib/modifier/index.js +2 -0
- package/lib/modifier/isRemoveParentItem.js +9 -0
- package/lib/order/addItem.js +33 -42
- package/lib/order/addItemModifier.js +1 -1
- package/lib/order/addModifiersToParentItem.js +41 -0
- package/lib/order/copyItemToParents.js +19 -0
- package/lib/order/getItemsWithParents.js +31 -0
- package/lib/order/index.js +6 -0
- package/lib/order/removeItem.js +17 -46
- package/lib/order/splitByDepartments.js +8 -3
- package/package.json +2 -2
- package/__TEST__/manualTest.test.js +0 -89
- package/lib/item/isParentIncluded.js +0 -4
package/__TEST__/item.test.js
CHANGED
|
@@ -1153,81 +1153,6 @@ describe('Item actions', () => {
|
|
|
1153
1153
|
expect(result.items).toMatchObject([item2]);
|
|
1154
1154
|
});
|
|
1155
1155
|
|
|
1156
|
-
test('Should add related item and its related addModifiers to the parent item, then removing that relateditem should also remove the mod from the parent item', () => {
|
|
1157
|
-
const rawRelatedItem1 = {
|
|
1158
|
-
name: 'the related item',
|
|
1159
|
-
_id: '67e2cadd8dcf08ebcc5ef888',
|
|
1160
|
-
};
|
|
1161
|
-
|
|
1162
|
-
const rawRelatedItem2 = {
|
|
1163
|
-
name: 'the 2nd related item',
|
|
1164
|
-
_id: '67e2cadd8dcf08ebcc5ef88a',
|
|
1165
|
-
};
|
|
1166
|
-
|
|
1167
|
-
const groupMod = {
|
|
1168
|
-
_id: '67e2cadd8dcf08ebcc5ef889',
|
|
1169
|
-
name: 'General Repair Department',
|
|
1170
|
-
attributes: ['group'],
|
|
1171
|
-
modifierId: 'mod1',
|
|
1172
|
-
properties: {
|
|
1173
|
-
group: {
|
|
1174
|
-
items: [],
|
|
1175
|
-
},
|
|
1176
|
-
},
|
|
1177
|
-
};
|
|
1178
|
-
|
|
1179
|
-
const parentItem = {
|
|
1180
|
-
name: 'the parent item',
|
|
1181
|
-
modifiers: [groupMod],
|
|
1182
|
-
_id: '67e2cadd8dcf08ebcc5ef887',
|
|
1183
|
-
__typename: 'OrderItem',
|
|
1184
|
-
};
|
|
1185
|
-
|
|
1186
|
-
const relatedItem1 = {
|
|
1187
|
-
...rawRelatedItem1,
|
|
1188
|
-
properties: {
|
|
1189
|
-
relatedItem: true,
|
|
1190
|
-
parentId: parentItem._id,
|
|
1191
|
-
includeParent: true,
|
|
1192
|
-
addModifiers: [groupMod],
|
|
1193
|
-
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
1194
|
-
},
|
|
1195
|
-
__typename: 'OrderItem',
|
|
1196
|
-
};
|
|
1197
|
-
|
|
1198
|
-
const relatedItem2 = {
|
|
1199
|
-
...rawRelatedItem2,
|
|
1200
|
-
properties: {
|
|
1201
|
-
relatedItem: true,
|
|
1202
|
-
parentId: parentItem._id,
|
|
1203
|
-
includeParent: true,
|
|
1204
|
-
addModifiers: [groupMod],
|
|
1205
|
-
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
1206
|
-
},
|
|
1207
|
-
__typename: 'OrderItem',
|
|
1208
|
-
};
|
|
1209
|
-
const order = {
|
|
1210
|
-
items: [parentItem, relatedItem1, relatedItem2],
|
|
1211
|
-
};
|
|
1212
|
-
|
|
1213
|
-
const result = pricingService.order.removeItem({
|
|
1214
|
-
order,
|
|
1215
|
-
item: relatedItem2,
|
|
1216
|
-
});
|
|
1217
|
-
|
|
1218
|
-
expect(result.items.length).toBe(2);
|
|
1219
|
-
expect(result.items[0].modifiers.length).toBe(1);
|
|
1220
|
-
expect(result.items[0].modifiers[0].modifierId).toBe('mod1');
|
|
1221
|
-
|
|
1222
|
-
const result2 = pricingService.order.removeItem({
|
|
1223
|
-
order: result,
|
|
1224
|
-
item: relatedItem1,
|
|
1225
|
-
});
|
|
1226
|
-
|
|
1227
|
-
expect(result2.items.length).toBe(1);
|
|
1228
|
-
expect(result2.items[0].modifiers.length).toBe(0);
|
|
1229
|
-
});
|
|
1230
|
-
|
|
1231
1156
|
test('Should not remove the group modifier if it still hasModifiers', () => {
|
|
1232
1157
|
const rawRelatedItem1 = {
|
|
1233
1158
|
name: 'the related item',
|
|
@@ -1283,7 +1208,7 @@ describe('Item actions', () => {
|
|
|
1283
1208
|
properties: {
|
|
1284
1209
|
relatedItem: true,
|
|
1285
1210
|
parentId: parentItem._id,
|
|
1286
|
-
|
|
1211
|
+
repairOnly: false,
|
|
1287
1212
|
addModifiers: [groupMod],
|
|
1288
1213
|
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
1289
1214
|
},
|
|
@@ -1295,7 +1220,7 @@ describe('Item actions', () => {
|
|
|
1295
1220
|
properties: {
|
|
1296
1221
|
relatedItem: true,
|
|
1297
1222
|
parentId: parentItem._id,
|
|
1298
|
-
|
|
1223
|
+
repairOnly: false,
|
|
1299
1224
|
addModifiers: [groupMod],
|
|
1300
1225
|
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
1301
1226
|
},
|
|
@@ -264,7 +264,7 @@ test('getInvalidRequiredModifiers having related items', () => {
|
|
|
264
264
|
relatedItem: true,
|
|
265
265
|
parentItemId: '62cdbfd01ee1b4001932821a',
|
|
266
266
|
parentId: '67dc63610c106ab7d481d7dd',
|
|
267
|
-
|
|
267
|
+
repairOnly: false,
|
|
268
268
|
groupPath: ',67dc63610c106ab7d481d7de',
|
|
269
269
|
},
|
|
270
270
|
},
|
|
@@ -1672,14 +1672,16 @@ describe('hasModifier Function', () => {
|
|
|
1672
1672
|
relatedItem: true,
|
|
1673
1673
|
parentItemId: item.itemId,
|
|
1674
1674
|
parentId: item._id,
|
|
1675
|
-
|
|
1675
|
+
repairOnly: false,
|
|
1676
1676
|
groupPath: ',groupMod10',
|
|
1677
|
+
removeParentItem: true,
|
|
1677
1678
|
},
|
|
1678
1679
|
},
|
|
1679
1680
|
});
|
|
1680
1681
|
|
|
1681
1682
|
expect(updatedOrder.items.length).toBe(2);
|
|
1682
|
-
|
|
1683
|
+
|
|
1684
|
+
const parentItem = {
|
|
1683
1685
|
_id: 1,
|
|
1684
1686
|
itemId: 'ab',
|
|
1685
1687
|
modifiers: [
|
|
@@ -1696,7 +1698,8 @@ describe('hasModifier Function', () => {
|
|
|
1696
1698
|
],
|
|
1697
1699
|
price: 500,
|
|
1698
1700
|
total: 10000,
|
|
1699
|
-
}
|
|
1701
|
+
};
|
|
1702
|
+
expect(updatedOrder.items[1]).toMatchObject(parentItem);
|
|
1700
1703
|
|
|
1701
1704
|
const result = pricingService.item.hasModifier({
|
|
1702
1705
|
item: updatedOrder.items[1],
|
|
@@ -1717,53 +1720,17 @@ describe('hasModifier Function', () => {
|
|
|
1717
1720
|
relatedItem: true,
|
|
1718
1721
|
parentItemId: item.itemId,
|
|
1719
1722
|
parentId: item._id,
|
|
1720
|
-
|
|
1723
|
+
repairOnly: true,
|
|
1721
1724
|
groupPath: ',groupMod10',
|
|
1725
|
+
removeParentItem: true,
|
|
1722
1726
|
},
|
|
1723
1727
|
},
|
|
1724
1728
|
});
|
|
1725
1729
|
|
|
1726
|
-
expect(updatedOrder2.items.length).toBe(
|
|
1727
|
-
|
|
1728
|
-
expect(updatedOrder2.items[1]).toMatchObject({
|
|
1729
|
-
_id: 1,
|
|
1730
|
-
itemId: 'ab',
|
|
1731
|
-
modifiers: [
|
|
1732
|
-
{
|
|
1733
|
-
_id: 'groupMod10',
|
|
1734
|
-
attributes: ['group'],
|
|
1735
|
-
properties: {
|
|
1736
|
-
group: {
|
|
1737
|
-
items: [{ _id: 'abc', name: 'related item abc', itemId: 'abc' }],
|
|
1738
|
-
modifiers: [{ _id: '123', name: 'related mod' }],
|
|
1739
|
-
},
|
|
1740
|
-
},
|
|
1741
|
-
conditions: { valid: true },
|
|
1742
|
-
compute: null,
|
|
1743
|
-
_computed: { amount: 0, description: 'undefined' },
|
|
1744
|
-
},
|
|
1745
|
-
],
|
|
1746
|
-
price: 0,
|
|
1747
|
-
total: 0,
|
|
1748
|
-
subTotals: {
|
|
1749
|
-
_included: 0,
|
|
1750
|
-
_xincluded: 0,
|
|
1751
|
-
_direct: 0,
|
|
1752
|
-
_xdirect: 0,
|
|
1753
|
-
_actual: 0,
|
|
1754
|
-
},
|
|
1755
|
-
});
|
|
1756
|
-
|
|
1757
|
-
const result2 = pricingService.item.hasModifier({
|
|
1758
|
-
item: updatedOrder2.items[1],
|
|
1759
|
-
modifier: groupMod,
|
|
1760
|
-
relatedItems: pricingService.order.getRelatedItems({
|
|
1761
|
-
order: updatedOrder2,
|
|
1762
|
-
item: updatedOrder2.items[1],
|
|
1763
|
-
}),
|
|
1764
|
-
});
|
|
1730
|
+
expect(updatedOrder2.items.length).toBe(1);
|
|
1731
|
+
expect(updatedOrder2.parentItems.length).toBe(1);
|
|
1765
1732
|
|
|
1766
|
-
expect(
|
|
1733
|
+
expect(updatedOrder2.parentItems[0]).toMatchObject(parentItem);
|
|
1767
1734
|
});
|
|
1768
1735
|
|
|
1769
1736
|
test('hasModifier, matching by spreadFrom', () => {
|
|
@@ -1800,4 +1767,107 @@ describe('hasModifier Function', () => {
|
|
|
1800
1767
|
|
|
1801
1768
|
expect(result).toBe(true);
|
|
1802
1769
|
});
|
|
1770
|
+
|
|
1771
|
+
test('hasModifier, using only 1 related items and keeping original item', () => {
|
|
1772
|
+
const relatedModItem = {
|
|
1773
|
+
_id: 'abc',
|
|
1774
|
+
name: 'related item abc',
|
|
1775
|
+
itemId: 'abc',
|
|
1776
|
+
};
|
|
1777
|
+
const groupMod = {
|
|
1778
|
+
_id: 'groupMod10',
|
|
1779
|
+
attributes: ['group'],
|
|
1780
|
+
properties: {
|
|
1781
|
+
group: {
|
|
1782
|
+
items: [relatedModItem],
|
|
1783
|
+
modifiers: [
|
|
1784
|
+
{
|
|
1785
|
+
_id: '123',
|
|
1786
|
+
name: 'related mod',
|
|
1787
|
+
},
|
|
1788
|
+
],
|
|
1789
|
+
},
|
|
1790
|
+
},
|
|
1791
|
+
};
|
|
1792
|
+
|
|
1793
|
+
const item = {
|
|
1794
|
+
_id: 1,
|
|
1795
|
+
itemId: 'ab',
|
|
1796
|
+
modifiers: [groupMod],
|
|
1797
|
+
price: 500,
|
|
1798
|
+
total: 10000,
|
|
1799
|
+
};
|
|
1800
|
+
|
|
1801
|
+
const order = {
|
|
1802
|
+
items: [item],
|
|
1803
|
+
modifiers: [],
|
|
1804
|
+
};
|
|
1805
|
+
|
|
1806
|
+
const { updatedOrder } = pricingService.order.addItem({
|
|
1807
|
+
order,
|
|
1808
|
+
item: {
|
|
1809
|
+
...relatedModItem,
|
|
1810
|
+
properties: {
|
|
1811
|
+
relatedItem: true,
|
|
1812
|
+
parentItemId: item.itemId,
|
|
1813
|
+
parentId: item._id,
|
|
1814
|
+
repairOnly: false,
|
|
1815
|
+
groupPath: ',groupMod10',
|
|
1816
|
+
},
|
|
1817
|
+
},
|
|
1818
|
+
});
|
|
1819
|
+
|
|
1820
|
+
expect(updatedOrder.items.length).toBe(2);
|
|
1821
|
+
|
|
1822
|
+
const parentItem = {
|
|
1823
|
+
_id: 1,
|
|
1824
|
+
itemId: 'ab',
|
|
1825
|
+
modifiers: [
|
|
1826
|
+
{
|
|
1827
|
+
_id: 'groupMod10',
|
|
1828
|
+
attributes: ['group'],
|
|
1829
|
+
properties: {
|
|
1830
|
+
group: {
|
|
1831
|
+
items: [{ _id: 'abc', name: 'related item abc', itemId: 'abc' }],
|
|
1832
|
+
modifiers: [{ _id: '123', name: 'related mod' }],
|
|
1833
|
+
},
|
|
1834
|
+
},
|
|
1835
|
+
},
|
|
1836
|
+
],
|
|
1837
|
+
price: 500,
|
|
1838
|
+
total: 10000,
|
|
1839
|
+
};
|
|
1840
|
+
expect(updatedOrder.items[1]).toMatchObject(parentItem);
|
|
1841
|
+
|
|
1842
|
+
const result = pricingService.item.hasModifier({
|
|
1843
|
+
item: updatedOrder.items[1],
|
|
1844
|
+
modifier: groupMod,
|
|
1845
|
+
relatedItems: pricingService.order.getRelatedItems({
|
|
1846
|
+
order: updatedOrder,
|
|
1847
|
+
item: updatedOrder.items[1],
|
|
1848
|
+
}),
|
|
1849
|
+
});
|
|
1850
|
+
|
|
1851
|
+
expect(result).toBe(true);
|
|
1852
|
+
|
|
1853
|
+
const relatedItemtoAdd = {
|
|
1854
|
+
...relatedModItem,
|
|
1855
|
+
properties: {
|
|
1856
|
+
relatedItem: true,
|
|
1857
|
+
parentItemId: item.itemId,
|
|
1858
|
+
parentId: item._id,
|
|
1859
|
+
repairOnly: false,
|
|
1860
|
+
groupPath: ',groupMod10',
|
|
1861
|
+
},
|
|
1862
|
+
};
|
|
1863
|
+
|
|
1864
|
+
const { updatedOrder: updatedOrder2 } = pricingService.order.addItem({
|
|
1865
|
+
order,
|
|
1866
|
+
item: relatedItemtoAdd,
|
|
1867
|
+
});
|
|
1868
|
+
|
|
1869
|
+
expect(updatedOrder2.items.length).toBe(2);
|
|
1870
|
+
expect(updatedOrder2.items[0].name).toBe('related item abc');
|
|
1871
|
+
expect(updatedOrder2.items[1]).toMatchObject(parentItem);
|
|
1872
|
+
});
|
|
1803
1873
|
});
|
|
@@ -231,7 +231,7 @@ describe('addItem function', () => {
|
|
|
231
231
|
relatedItem: true,
|
|
232
232
|
parentItemId: updatedOrder.items[0].itemId,
|
|
233
233
|
parentId: updatedOrder.items[0]._id,
|
|
234
|
-
|
|
234
|
+
repairOnly: false,
|
|
235
235
|
addModifiers: [
|
|
236
236
|
{
|
|
237
237
|
_id: 'mod1',
|
|
@@ -270,7 +270,7 @@ describe('addItem function', () => {
|
|
|
270
270
|
relatedItem: true,
|
|
271
271
|
parentItemId: updatedOrder.items[0].itemId,
|
|
272
272
|
parentId: updatedOrder.items[0]._id,
|
|
273
|
-
|
|
273
|
+
repairOnly: false,
|
|
274
274
|
addModifiers: [
|
|
275
275
|
{
|
|
276
276
|
_id: 'mod1',
|
|
@@ -3858,4 +3858,79 @@ describe('Order actions', () => {
|
|
|
3858
3858
|
);
|
|
3859
3859
|
expect(newOrder.items[2].total).toEqual(7.44);
|
|
3860
3860
|
});
|
|
3861
|
+
|
|
3862
|
+
test('Should return same items if there are no related items', () => {
|
|
3863
|
+
const items = [
|
|
3864
|
+
{ _id: '1', properties: {} },
|
|
3865
|
+
{ _id: '2', properties: {} },
|
|
3866
|
+
];
|
|
3867
|
+
const parentItems = [{ _id: '10', properties: {} }];
|
|
3868
|
+
|
|
3869
|
+
const result = pricingService.order.getItemsWithParents({
|
|
3870
|
+
items,
|
|
3871
|
+
parentItems,
|
|
3872
|
+
});
|
|
3873
|
+
|
|
3874
|
+
expect(result).toEqual(items);
|
|
3875
|
+
});
|
|
3876
|
+
|
|
3877
|
+
test('Should insert missing parent before first related item', () => {
|
|
3878
|
+
const items = [
|
|
3879
|
+
{ _id: '1', properties: {} },
|
|
3880
|
+
{ _id: '2', properties: { parentId: '10', relatedItem: true } },
|
|
3881
|
+
{ _id: '3', properties: {} },
|
|
3882
|
+
];
|
|
3883
|
+
|
|
3884
|
+
const parentItems = [
|
|
3885
|
+
{ _id: '10', properties: {} },
|
|
3886
|
+
{ _id: '11', properties: {} },
|
|
3887
|
+
];
|
|
3888
|
+
|
|
3889
|
+
const result = pricingService.order.getItemsWithParents({
|
|
3890
|
+
items,
|
|
3891
|
+
parentItems,
|
|
3892
|
+
});
|
|
3893
|
+
|
|
3894
|
+
expect(result).toEqual([
|
|
3895
|
+
{ _id: '1', properties: {} },
|
|
3896
|
+
{ _id: '10', properties: {} },
|
|
3897
|
+
{ _id: '2', properties: { parentId: '10', relatedItem: true } },
|
|
3898
|
+
{ _id: '3', properties: {} },
|
|
3899
|
+
]);
|
|
3900
|
+
});
|
|
3901
|
+
|
|
3902
|
+
test('Should not duplicate parent if already inserted', () => {
|
|
3903
|
+
const items = [
|
|
3904
|
+
{ _id: '2', properties: { parentId: '10', relatedItem: true } },
|
|
3905
|
+
{ _id: '3', properties: { parentId: '10', relatedItem: true } },
|
|
3906
|
+
];
|
|
3907
|
+
|
|
3908
|
+
const parentItems = [{ _id: '10', properties: {} }];
|
|
3909
|
+
|
|
3910
|
+
const result = pricingService.order.getItemsWithParents({
|
|
3911
|
+
items,
|
|
3912
|
+
parentItems,
|
|
3913
|
+
});
|
|
3914
|
+
|
|
3915
|
+
const parentCount = result.filter(i => i._id === '10').length;
|
|
3916
|
+
expect(parentCount).toBe(1);
|
|
3917
|
+
expect(result[0]._id).toBe('10');
|
|
3918
|
+
});
|
|
3919
|
+
|
|
3920
|
+
test('Should skip injection if parent already exists in items', () => {
|
|
3921
|
+
const items = [
|
|
3922
|
+
{ _id: '10', properties: {} },
|
|
3923
|
+
{ _id: '2', properties: { parentId: '10', relatedItem: true } },
|
|
3924
|
+
];
|
|
3925
|
+
const parentItems = [{ _id: '10', properties: {} }];
|
|
3926
|
+
|
|
3927
|
+
const result = pricingService.order.getItemsWithParents({
|
|
3928
|
+
items,
|
|
3929
|
+
parentItems,
|
|
3930
|
+
});
|
|
3931
|
+
|
|
3932
|
+
const parentCount = result.filter(i => i._id === '10').length;
|
|
3933
|
+
expect(parentCount).toBe(1);
|
|
3934
|
+
expect(result).toEqual(items);
|
|
3935
|
+
});
|
|
3861
3936
|
});
|
|
@@ -522,6 +522,16 @@ describe('Auto Split', () => {
|
|
|
522
522
|
__typename: 'Modifier',
|
|
523
523
|
};
|
|
524
524
|
|
|
525
|
+
const parentItem = {
|
|
526
|
+
name: "2pc Men's Suit",
|
|
527
|
+
modifiers: [dtModifier],
|
|
528
|
+
_id: '686d62b3e0f59b1de5d93b28',
|
|
529
|
+
pieces: 2,
|
|
530
|
+
quantity: 1,
|
|
531
|
+
weight: 0,
|
|
532
|
+
properties: {},
|
|
533
|
+
};
|
|
534
|
+
|
|
525
535
|
const parentOrder = {
|
|
526
536
|
_id: '686d62ace0f59b1de5d93b27',
|
|
527
537
|
|
|
@@ -535,19 +545,12 @@ describe('Auto Split', () => {
|
|
|
535
545
|
relatedItem: true,
|
|
536
546
|
parentItemId: '67fea241af24e570c032b319',
|
|
537
547
|
parentId: '686d62b3e0f59b1de5d93b28',
|
|
538
|
-
|
|
548
|
+
repairOnly: false,
|
|
539
549
|
},
|
|
540
550
|
},
|
|
541
|
-
|
|
542
|
-
name: "2pc Men's Suit",
|
|
543
|
-
modifiers: [dtModifier],
|
|
544
|
-
_id: '686d62b3e0f59b1de5d93b28',
|
|
545
|
-
pieces: 2,
|
|
546
|
-
quantity: 1,
|
|
547
|
-
weight: 0,
|
|
548
|
-
properties: {},
|
|
549
|
-
},
|
|
551
|
+
parentItem,
|
|
550
552
|
],
|
|
553
|
+
parentItems: [parentItem],
|
|
551
554
|
modifiers: [],
|
|
552
555
|
status: {},
|
|
553
556
|
};
|
|
@@ -644,7 +647,7 @@ describe('Auto Split', () => {
|
|
|
644
647
|
relatedItem: true,
|
|
645
648
|
parentItemId: '67fea241af24e570c032b319',
|
|
646
649
|
parentId: '686d62b3e0f59b1de5d93b28',
|
|
647
|
-
|
|
650
|
+
repairOnly: false,
|
|
648
651
|
},
|
|
649
652
|
},
|
|
650
653
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module.exports = ({ actions, modifierActions }) =>
|
|
2
|
-
function getSplitDepartment({
|
|
2
|
+
function getSplitDepartment({ parentItems, item }) {
|
|
3
3
|
if (actions.isRelatedItem(item)) {
|
|
4
|
-
const parentItem = actions.getParentItem(
|
|
4
|
+
const parentItem = actions.getParentItem(parentItems, item);
|
|
5
5
|
|
|
6
6
|
if (parentItem) {
|
|
7
7
|
const parentDeps = actions.getDepartmentModifiers(parentItem);
|
package/lib/item/index.js
CHANGED
|
@@ -25,7 +25,7 @@ const getItemsTotalPaid = require('./getItemsTotalPaid');
|
|
|
25
25
|
const getModifierTags = require('./getModifierTags');
|
|
26
26
|
const isRelatedItem = require('./isRelatedItem');
|
|
27
27
|
const getParentItem = require('./getParentItem');
|
|
28
|
-
const
|
|
28
|
+
const isRepairOnly = require('./isRepairOnly');
|
|
29
29
|
const hasCreateSubscription = require('./hasCreateSubscription');
|
|
30
30
|
const getItemModifiers = require('./getItemModifiers');
|
|
31
31
|
const getItemsBalance = require('./getItemsBalance');
|
|
@@ -46,8 +46,6 @@ const getBasePrice = require('./getBasePrice');
|
|
|
46
46
|
const validateModifiersByQuantity = require('./validateModifiersByQuantity');
|
|
47
47
|
const getModifiersBySingleValueId = require('./getModifiersBySingleValueId');
|
|
48
48
|
const getLastLocation = require('./getLastLocation');
|
|
49
|
-
const hasAddModifiers = require('./hasAddModifiers');
|
|
50
|
-
const getAddModifiers = require('./getAddModifiers');
|
|
51
49
|
const getRelatedItems = require('./getRelatedItems');
|
|
52
50
|
const getRelatedModifiers = require('./getRelatedModifiers');
|
|
53
51
|
const unpickItem = require('./unpick');
|
|
@@ -74,6 +72,11 @@ const isPriceChanged = require('./isPriceChanged');
|
|
|
74
72
|
const isSerialRequired = require('./isSerialRequired');
|
|
75
73
|
const isSerialLengthValid = require('./isSerialLengthValid');
|
|
76
74
|
const getSerialStatus = require('./getSerialStatus');
|
|
75
|
+
const removeDepartmentModifiers = require('./removeDepartmentModifiers');
|
|
76
|
+
const isRemoveParentItem = require('./isRemoveParentItem');
|
|
77
|
+
const hasRelatedItems = require('./hasRelatedItems');
|
|
78
|
+
const getAddModifiers = require('./getAddModifiers');
|
|
79
|
+
const hasAddModifiers = require('./hasAddModifiers');
|
|
77
80
|
|
|
78
81
|
const itemActions = (deps = {}) => {
|
|
79
82
|
const actions = {};
|
|
@@ -111,7 +114,7 @@ const itemActions = (deps = {}) => {
|
|
|
111
114
|
getModifierTags: getModifierTags(innerDeps),
|
|
112
115
|
isRelatedItem: isRelatedItem(innerDeps),
|
|
113
116
|
getParentItem: getParentItem(innerDeps),
|
|
114
|
-
|
|
117
|
+
isRepairOnly: isRepairOnly(innerDeps),
|
|
115
118
|
hasCreateSubscription: hasCreateSubscription(innerDeps),
|
|
116
119
|
getItemModifiers: getItemModifiers(innerDeps),
|
|
117
120
|
getItemsBalance: getItemsBalance(innerDeps),
|
|
@@ -133,8 +136,6 @@ const itemActions = (deps = {}) => {
|
|
|
133
136
|
validateModifiersByQuantity: validateModifiersByQuantity(innerDeps),
|
|
134
137
|
getModifiersBySingleValueId: getModifiersBySingleValueId(innerDeps),
|
|
135
138
|
getLastLocation: getLastLocation(innerDeps),
|
|
136
|
-
hasAddModifiers: hasAddModifiers(innerDeps),
|
|
137
|
-
getAddModifiers: getAddModifiers(innerDeps),
|
|
138
139
|
getRelatedItems: getRelatedItems(innerDeps),
|
|
139
140
|
getRelatedModifiers: getRelatedModifiers(innerDeps),
|
|
140
141
|
unpickItem: unpickItem(innerDeps),
|
|
@@ -161,6 +162,11 @@ const itemActions = (deps = {}) => {
|
|
|
161
162
|
isSerialRequired: isSerialRequired(innerDeps),
|
|
162
163
|
isSerialLengthValid: isSerialLengthValid(innerDeps),
|
|
163
164
|
getSerialStatus: getSerialStatus(innerDeps),
|
|
165
|
+
removeDepartmentModifiers: removeDepartmentModifiers(innerDeps),
|
|
166
|
+
isRemoveParentItem: isRemoveParentItem(innerDeps),
|
|
167
|
+
hasRelatedItems: hasRelatedItems(innerDeps),
|
|
168
|
+
getAddModifiers: getAddModifiers(innerDeps),
|
|
169
|
+
hasAddModifiers: hasAddModifiers(innerDeps),
|
|
164
170
|
});
|
|
165
171
|
|
|
166
172
|
Object.keys(freezedActions).forEach(actionName => {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module.exports = ({ actions, modifierActions }) =>
|
|
2
|
+
function removeDepartmentModifiers({ item, order }) {
|
|
3
|
+
if (!item) return undefined;
|
|
4
|
+
if (!Array.isArray(item.modifiers)) return item;
|
|
5
|
+
const deparmentModifiers = item.modifiers.filter(mod =>
|
|
6
|
+
modifierActions.isDepartment(mod)
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
const newItem = deparmentModifiers.reduce(
|
|
10
|
+
(nextItem, modifier) =>
|
|
11
|
+
actions.removeModifier({
|
|
12
|
+
item: nextItem,
|
|
13
|
+
modifier,
|
|
14
|
+
order,
|
|
15
|
+
}),
|
|
16
|
+
item
|
|
17
|
+
);
|
|
18
|
+
return newItem;
|
|
19
|
+
};
|
|
@@ -1,30 +1,14 @@
|
|
|
1
|
-
module.exports = ({ actions }) =>
|
|
2
|
-
|
|
1
|
+
module.exports = ({ actions }) =>
|
|
2
|
+
function getInheritedModifiers({ parentItem }) {
|
|
3
|
+
if (!parentItem || !Array.isArray(parentItem.modifiers)) return [];
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
if (!parentItem || !childItem) return [];
|
|
5
|
+
const modifiersToAdd = [];
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
parentItem.modifiers.forEach(parentMod => {
|
|
8
|
+
if (!actions.isDepartment(parentMod) && !actions.isGroup(parentMod)) {
|
|
9
|
+
modifiersToAdd.push(parentMod);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
if (!relatedItemModifier) return modifiers;
|
|
13
|
-
|
|
14
|
-
const { properties = {} } = relatedItemModifier;
|
|
15
|
-
const items = (properties.group && properties.group.items) || [];
|
|
16
|
-
|
|
17
|
-
const relatedItem = items.find(each => each._id === _id);
|
|
18
|
-
if (!relatedItem) return [];
|
|
19
|
-
|
|
20
|
-
if (properties.inheritModifiers && parentModifiers.length) {
|
|
21
|
-
const inheritedModifiers = parentModifiers
|
|
22
|
-
.filter(each => !isRelated(each))
|
|
23
|
-
.map(each => actions.duplicate(each));
|
|
24
|
-
|
|
25
|
-
if (inheritedModifiers.length) modifiers.push(...inheritedModifiers);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return modifiers;
|
|
13
|
+
return modifiersToAdd;
|
|
29
14
|
};
|
|
30
|
-
};
|
package/lib/modifier/index.js
CHANGED
|
@@ -181,6 +181,7 @@ const getPromoCustomerIds = require('./getPromoCustomerIds');
|
|
|
181
181
|
const getCountPerCustomer = require('./getCountPerCustomer');
|
|
182
182
|
const getAmountMultiplier = require('./getAmountMultiplier');
|
|
183
183
|
const isAmountMultiplier = require('./isAmountMultiplier');
|
|
184
|
+
const isRemoveParentItem = require('./isRemoveParentItem');
|
|
184
185
|
|
|
185
186
|
const modifierActions = (deps = {}) => {
|
|
186
187
|
const actions = {};
|
|
@@ -374,6 +375,7 @@ const modifierActions = (deps = {}) => {
|
|
|
374
375
|
getCountPerCustomer: getCountPerCustomer(innerDeps),
|
|
375
376
|
getAmountMultiplier: getAmountMultiplier(innerDeps),
|
|
376
377
|
isAmountMultiplier: isAmountMultiplier(innerDeps),
|
|
378
|
+
isRemoveParentItem: isRemoveParentItem(innerDeps),
|
|
377
379
|
});
|
|
378
380
|
|
|
379
381
|
Object.keys(freezedActions).forEach(actionName => {
|
package/lib/order/addItem.js
CHANGED
|
@@ -147,7 +147,11 @@ module.exports = ({ actions, itemActions, modifierActions, settings, _ }) => {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
if (
|
|
150
|
+
if (
|
|
151
|
+
autoBarcode &&
|
|
152
|
+
!orderItem.serial &&
|
|
153
|
+
!itemActions.isRelatedItem(orderItem)
|
|
154
|
+
) {
|
|
151
155
|
orderItem.serial = autoBarcode;
|
|
152
156
|
}
|
|
153
157
|
|
|
@@ -164,17 +168,30 @@ module.exports = ({ actions, itemActions, modifierActions, settings, _ }) => {
|
|
|
164
168
|
item: orderItem,
|
|
165
169
|
});
|
|
166
170
|
if (itemActions.isRelatedItem(orderItem)) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
parent,
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
171
|
+
let parent = itemActions.getParentItem(order.parentItems, orderItem);
|
|
172
|
+
|
|
173
|
+
if (!parent) {
|
|
174
|
+
parent = itemActions.getParentItem(order.items, orderItem);
|
|
175
|
+
order = actions.copyItemToParents({ order, item: parent });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
modifiersToAdd.push(
|
|
179
|
+
...modifierActions.getInheritedModifiers({ parentItem: parent })
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
orderItem.serial = parent.serial;
|
|
183
|
+
|
|
184
|
+
if (parent && itemActions.isRepairOnly(orderItem)) {
|
|
185
|
+
if (itemActions.isRemoveParentItem(item)) {
|
|
186
|
+
order = actions.removeItem({
|
|
187
|
+
order,
|
|
188
|
+
item: parent,
|
|
189
|
+
skipParentsCheck: true,
|
|
190
|
+
keepRelatedItems: true,
|
|
191
|
+
});
|
|
192
|
+
} else {
|
|
193
|
+
order = actions.resetItem({ order, item: parent });
|
|
194
|
+
}
|
|
178
195
|
}
|
|
179
196
|
}
|
|
180
197
|
}
|
|
@@ -248,36 +265,10 @@ module.exports = ({ actions, itemActions, modifierActions, settings, _ }) => {
|
|
|
248
265
|
nextOrder.items.splice(idxToRemove, 1);
|
|
249
266
|
}
|
|
250
267
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
) {
|
|
256
|
-
const parentItem = itemActions.getParentItem(nextOrder.items, item);
|
|
257
|
-
const parentIndex = actions.getItemIndex({
|
|
258
|
-
order: nextOrder,
|
|
259
|
-
item: parentItem,
|
|
260
|
-
});
|
|
261
|
-
const relatedModifiersToAdd = itemActions
|
|
262
|
-
.getAddModifiers(item)
|
|
263
|
-
.filter(
|
|
264
|
-
mod =>
|
|
265
|
-
!parentItem.modifiers.some(
|
|
266
|
-
itemMod => itemMod.modifierId === mod._id
|
|
267
|
-
)
|
|
268
|
-
);
|
|
269
|
-
|
|
270
|
-
nextOrder = relatedModifiersToAdd.reduce(
|
|
271
|
-
(acc, modifier) =>
|
|
272
|
-
actions.addItemModifier({
|
|
273
|
-
itemIndex: parentIndex,
|
|
274
|
-
order: acc,
|
|
275
|
-
modifier,
|
|
276
|
-
originalItem: parentItem,
|
|
277
|
-
}),
|
|
278
|
-
nextOrder
|
|
279
|
-
);
|
|
280
|
-
}
|
|
268
|
+
nextOrder = actions.addModifiersToParentItem({
|
|
269
|
+
order: nextOrder,
|
|
270
|
+
relatedItem: orderItem,
|
|
271
|
+
});
|
|
281
272
|
|
|
282
273
|
return {
|
|
283
274
|
updatedOrder: nextOrder,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module.exports = ({ actions, itemActions }) =>
|
|
2
|
+
function addModifiersToParentItem({ order, relatedItem }) {
|
|
3
|
+
if (
|
|
4
|
+
!order ||
|
|
5
|
+
!itemActions.isRelatedItem(relatedItem) ||
|
|
6
|
+
!itemActions.hasAddModifiers(relatedItem) ||
|
|
7
|
+
itemActions.isRepairOnly(relatedItem)
|
|
8
|
+
) {
|
|
9
|
+
return order;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let nextOrder = { ...order };
|
|
13
|
+
|
|
14
|
+
const parentItem = itemActions.getParentItem(nextOrder.items, relatedItem);
|
|
15
|
+
const parentIndex = actions.getItemIndex({
|
|
16
|
+
order: nextOrder,
|
|
17
|
+
item: parentItem,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (parentIndex < 0) return nextOrder;
|
|
21
|
+
|
|
22
|
+
const relatedModifiersToAdd = itemActions
|
|
23
|
+
.getAddModifiers(relatedItem)
|
|
24
|
+
.filter(
|
|
25
|
+
mod =>
|
|
26
|
+
!parentItem.modifiers.some(itemMod => itemMod.modifierId === mod._id)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
nextOrder = relatedModifiersToAdd.reduce(
|
|
30
|
+
(acc, modifier) =>
|
|
31
|
+
actions.addItemModifier({
|
|
32
|
+
itemIndex: parentIndex,
|
|
33
|
+
order: acc,
|
|
34
|
+
modifier,
|
|
35
|
+
originalItem: parentItem,
|
|
36
|
+
}),
|
|
37
|
+
nextOrder
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return nextOrder;
|
|
41
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module.exports = ({ itemActions }) =>
|
|
2
|
+
function copyItemToParents({ item, order }) {
|
|
3
|
+
if (!order || !item || itemActions.isRelatedItem(item)) return order;
|
|
4
|
+
if (!item._id) return order;
|
|
5
|
+
|
|
6
|
+
const alreadyExists =
|
|
7
|
+
order.parentItems &&
|
|
8
|
+
order.parentItems.some(parentItem => parentItem._id === item._id);
|
|
9
|
+
|
|
10
|
+
if (alreadyExists) return order;
|
|
11
|
+
|
|
12
|
+
const parentItems = Array.isArray(order.parentItems)
|
|
13
|
+
? [...order.parentItems]
|
|
14
|
+
: [];
|
|
15
|
+
|
|
16
|
+
parentItems.push(item);
|
|
17
|
+
|
|
18
|
+
return { ...order, parentItems };
|
|
19
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module.exports = ({ itemActions }) =>
|
|
2
|
+
function getItemsWithParents({ items, parentItems }) {
|
|
3
|
+
if (!Array.isArray(items)) return [];
|
|
4
|
+
|
|
5
|
+
if (!Array.isArray(parentItems) || parentItems.length === 0) return items;
|
|
6
|
+
|
|
7
|
+
const result = [];
|
|
8
|
+
|
|
9
|
+
items.forEach(item => {
|
|
10
|
+
if (!itemActions.isRelatedItem(item)) {
|
|
11
|
+
result.push(item);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const parentId =
|
|
16
|
+
item && item.properties ? item.properties.parentId : undefined;
|
|
17
|
+
const parentInOrder = items.find(p => p && p._id === parentId);
|
|
18
|
+
const parentInParentItems = parentItems.find(
|
|
19
|
+
p => p && p._id === parentId
|
|
20
|
+
);
|
|
21
|
+
const parentInResult = result.find(i => i && i._id === parentId);
|
|
22
|
+
|
|
23
|
+
if (!parentInOrder && parentInParentItems && !parentInResult) {
|
|
24
|
+
result.push(parentInParentItems);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
result.push(item);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return result;
|
|
31
|
+
};
|
package/lib/order/index.js
CHANGED
|
@@ -92,6 +92,9 @@ const mapSubOrders = require('./mapSubOrders');
|
|
|
92
92
|
const isFullyPaid = require('./isFullyPaid');
|
|
93
93
|
const getUpdatedStatus = require('./getUpdatedStatus');
|
|
94
94
|
const setPieces = require('./setPieces');
|
|
95
|
+
const copyItemToParents = require('./copyItemToParents');
|
|
96
|
+
const getItemsWithParents = require('./getItemsWithParents');
|
|
97
|
+
const addModifiersToParentItem = require('./addModifiersToParentItem');
|
|
95
98
|
|
|
96
99
|
const orderActions = (deps = {}) => {
|
|
97
100
|
const actions = {};
|
|
@@ -195,6 +198,9 @@ const orderActions = (deps = {}) => {
|
|
|
195
198
|
isFullyPaid: isFullyPaid(innerDeps),
|
|
196
199
|
getUpdatedStatus: getUpdatedStatus(innerDeps),
|
|
197
200
|
setPieces: setPieces(innerDeps),
|
|
201
|
+
copyItemToParents: copyItemToParents(innerDeps),
|
|
202
|
+
getItemsWithParents: getItemsWithParents(innerDeps),
|
|
203
|
+
addModifiersToParentItem: addModifiersToParentItem(innerDeps),
|
|
198
204
|
});
|
|
199
205
|
|
|
200
206
|
Object.keys(freezedActions).forEach(actionName => {
|
package/lib/order/removeItem.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module.exports = ({ actions, itemActions }) => {
|
|
2
|
-
const remove = ({ order, item, checkQuantity }) => {
|
|
2
|
+
const remove = ({ order, item, checkQuantity, keepRelatedItems }) => {
|
|
3
3
|
const orderItemIdx = actions.getItemIndex({ order, item });
|
|
4
4
|
if (orderItemIdx < 0) return order;
|
|
5
5
|
|
|
@@ -19,53 +19,12 @@ module.exports = ({ actions, itemActions }) => {
|
|
|
19
19
|
|
|
20
20
|
items.splice(orderItemIdx, 1);
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const resultedOrder = {
|
|
23
23
|
...order,
|
|
24
24
|
items,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
if (
|
|
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
|
-
})
|
|
42
|
-
) {
|
|
43
|
-
const updatedItem = itemActions.removeModifier({
|
|
44
|
-
item: parentItem,
|
|
45
|
-
modifier: addModifier,
|
|
46
|
-
originalItem: parentItem,
|
|
47
|
-
});
|
|
48
|
-
const itemIndexToUpdate = actions.getItemIndex({
|
|
49
|
-
order: prevOrder,
|
|
50
|
-
item: parentItem,
|
|
51
|
-
});
|
|
52
|
-
if (itemIndexToUpdate >= 0) {
|
|
53
|
-
const itemsToUpdate = [...prevOrder.items];
|
|
54
|
-
|
|
55
|
-
itemsToUpdate.splice(itemIndexToUpdate, 1, updatedItem);
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
...resultedOrder,
|
|
59
|
-
items: itemsToUpdate,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return resultedOrder;
|
|
64
|
-
},
|
|
65
|
-
resultedOrder
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
27
|
+
if (keepRelatedItems) return resultedOrder;
|
|
69
28
|
|
|
70
29
|
const relatedItems = actions.getRelatedItems({ order, item });
|
|
71
30
|
if (relatedItems.length > 0) {
|
|
@@ -83,10 +42,22 @@ module.exports = ({ actions, itemActions }) => {
|
|
|
83
42
|
return resultedOrder;
|
|
84
43
|
};
|
|
85
44
|
|
|
86
|
-
return function removeItem({
|
|
45
|
+
return function removeItem({
|
|
46
|
+
order,
|
|
47
|
+
item,
|
|
48
|
+
checkQuantity,
|
|
49
|
+
skipParentsCheck,
|
|
50
|
+
keepRelatedItems,
|
|
51
|
+
}) {
|
|
87
52
|
if (!order || !Array.isArray(order.items) || !item) return order;
|
|
88
53
|
|
|
89
|
-
const nextOrder = remove({ order, item, checkQuantity });
|
|
54
|
+
const nextOrder = remove({ order, item, checkQuantity, keepRelatedItems });
|
|
55
|
+
|
|
56
|
+
if (!skipParentsCheck && Array.isArray(nextOrder.parentItems)) {
|
|
57
|
+
nextOrder.parentItems = nextOrder.parentItems.filter(parentItem =>
|
|
58
|
+
itemActions.hasRelatedItems({ parentItem, items: nextOrder.items })
|
|
59
|
+
);
|
|
60
|
+
}
|
|
90
61
|
|
|
91
62
|
return nextOrder;
|
|
92
63
|
};
|
|
@@ -49,8 +49,13 @@ module.exports = ({
|
|
|
49
49
|
return Number(aIsRelated) - Number(bIsRelated);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
const { parentItems } = parentOrderParam;
|
|
53
|
+
|
|
52
54
|
const itemsByDepartments = _.groupBy(sortedItems, item =>
|
|
53
|
-
itemActions.getSplitDepartment({
|
|
55
|
+
itemActions.getSplitDepartment({
|
|
56
|
+
parentItems,
|
|
57
|
+
item,
|
|
58
|
+
})
|
|
54
59
|
);
|
|
55
60
|
const itemGroups = Object.values(itemsByDepartments);
|
|
56
61
|
let splitOrders = [];
|
|
@@ -64,7 +69,7 @@ module.exports = ({
|
|
|
64
69
|
// Assuming there is one department in the item
|
|
65
70
|
const department = itemActions.getDepartmentModifiers(items[0])[0];
|
|
66
71
|
const departmentName = itemActions.getSplitDepartment({
|
|
67
|
-
|
|
72
|
+
parentItems,
|
|
68
73
|
item: items[0],
|
|
69
74
|
});
|
|
70
75
|
const maxItems = modifierActions.getDepartmentMaxItems(department);
|
|
@@ -129,7 +134,7 @@ module.exports = ({
|
|
|
129
134
|
maxItems &&
|
|
130
135
|
departmentName ===
|
|
131
136
|
itemActions.getSplitDepartment({
|
|
132
|
-
|
|
137
|
+
parentItems,
|
|
133
138
|
item: items[0],
|
|
134
139
|
})
|
|
135
140
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.133",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"supertest": "^6.2.3",
|
|
53
53
|
"supervisor": "^0.12.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "1cec04f4a6fc32238922712068994984b62ab92d"
|
|
56
56
|
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
const usePricing = require('../index');
|
|
2
|
-
const mockStores = require('./mocks/stores');
|
|
3
|
-
|
|
4
|
-
const session = {
|
|
5
|
-
store: mockStores[0],
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const pricingService = usePricing(session);
|
|
9
|
-
|
|
10
|
-
describe('Manual actions', () => {
|
|
11
|
-
test('Should add related item and its related addModifiers to the parent item, then removing that relateditem should also remove the mod from the parent item', () => {
|
|
12
|
-
const rawRelatedItem1 = {
|
|
13
|
-
name: 'the related item',
|
|
14
|
-
_id: '67e2cadd8dcf08ebcc5ef888',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const rawRelatedItem2 = {
|
|
18
|
-
name: 'the 2nd related item',
|
|
19
|
-
_id: '67e2cadd8dcf08ebcc5ef88a',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const groupMod = {
|
|
23
|
-
_id: '67e2cadd8dcf08ebcc5ef889',
|
|
24
|
-
name: 'General Repair Department',
|
|
25
|
-
attributes: ['group'],
|
|
26
|
-
modifierId: 'mod1',
|
|
27
|
-
properties: {
|
|
28
|
-
group: {
|
|
29
|
-
items: [],
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const parentItem = {
|
|
35
|
-
name: 'the parent item',
|
|
36
|
-
modifiers: [groupMod],
|
|
37
|
-
_id: '67e2cadd8dcf08ebcc5ef887',
|
|
38
|
-
__typename: 'OrderItem',
|
|
39
|
-
|
|
40
|
-
itemId: 'abcd123',
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const relatedItem1 = {
|
|
44
|
-
...rawRelatedItem1,
|
|
45
|
-
properties: {
|
|
46
|
-
relatedItem: true,
|
|
47
|
-
parentId: parentItem._id,
|
|
48
|
-
parentItemId: parentItem.itemId,
|
|
49
|
-
includeParent: true,
|
|
50
|
-
addModifiers: [groupMod],
|
|
51
|
-
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
52
|
-
},
|
|
53
|
-
__typename: 'OrderItem',
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const relatedItem2 = {
|
|
57
|
-
...rawRelatedItem2,
|
|
58
|
-
properties: {
|
|
59
|
-
relatedItem: true,
|
|
60
|
-
parentId: parentItem._id,
|
|
61
|
-
parentItemId: parentItem.itemId,
|
|
62
|
-
includeParent: true,
|
|
63
|
-
addModifiers: [groupMod],
|
|
64
|
-
groupPath: ',67e2cadd8dcf08ebcc5ef889',
|
|
65
|
-
},
|
|
66
|
-
__typename: 'OrderItem',
|
|
67
|
-
};
|
|
68
|
-
const order = {
|
|
69
|
-
items: [parentItem, relatedItem1, relatedItem2],
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const result = pricingService.order.removeItem({
|
|
73
|
-
order,
|
|
74
|
-
item: relatedItem2,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
expect(result.items.length).toBe(2);
|
|
78
|
-
expect(result.items[0].modifiers.length).toBe(1);
|
|
79
|
-
expect(result.items[0].modifiers[0].modifierId).toBe('mod1');
|
|
80
|
-
|
|
81
|
-
// const result2 = pricingService.order.removeItem({
|
|
82
|
-
// order: result,
|
|
83
|
-
// item: relatedItem1,
|
|
84
|
-
// });
|
|
85
|
-
|
|
86
|
-
// expect(result2.items.length).toBe(1);
|
|
87
|
-
// expect(result2.items[0].modifiers.length).toBe(0);
|
|
88
|
-
});
|
|
89
|
-
});
|