@softwear/latestcollectioncore 1.0.197 → 1.0.198
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/dist/articleStatus.d.ts +0 -4
- package/dist/articleStatus.js +7 -3
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/articleStatus.ts +8 -3
- package/src/types.ts +1 -0
- package/test/articleStatus.spec.js +55 -0
package/dist/articleStatus.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { TransactionI, RaGI, HrTimeframeI, TimeGranularityE, SkuI } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* The propFunction for FiltreX needs some data that can't be passed as parameters. That's why the 'globalsRelations' variable is needed.
|
|
4
|
-
* TODO: Functional: Experiment with curried functions
|
|
5
|
-
*/
|
|
6
2
|
declare function propFunction(propertyName: string, getPropertyName: Function, obj: Record<string, any>): any;
|
|
7
3
|
declare function whichShardsToProcess(dateRange: any, granularity: 'year' | 'month'): any[];
|
|
8
4
|
/**
|
package/dist/articleStatus.js
CHANGED
|
@@ -29,16 +29,20 @@ let globalNrAggegationExpressions = 0; // tracks the # aggregations rows so we c
|
|
|
29
29
|
* The propFunction for FiltreX needs some data that can't be passed as parameters. That's why the 'globalsRelations' variable is needed.
|
|
30
30
|
* TODO: Functional: Experiment with curried functions
|
|
31
31
|
*/
|
|
32
|
+
function resolvePath(obj, path) {
|
|
33
|
+
return path.reduce((o, key) => o === null || o === void 0 ? void 0 : o[key], obj);
|
|
34
|
+
}
|
|
32
35
|
function propFunction(propertyName, getPropertyName, obj) {
|
|
33
36
|
var _a, _b;
|
|
34
37
|
const positionOfDot = propertyName.indexOf('.');
|
|
35
38
|
if (positionOfDot < 0)
|
|
36
39
|
return obj[propertyName];
|
|
37
40
|
const table = propertyName.substring(0, positionOfDot);
|
|
38
|
-
const
|
|
41
|
+
const path = propertyName.substring(positionOfDot + 1).split('.');
|
|
39
42
|
if (table == 'transaction')
|
|
40
|
-
return obj
|
|
41
|
-
|
|
43
|
+
return resolvePath(obj, path);
|
|
44
|
+
const joinedRecord = (_a = globalRelations[table]) === null || _a === void 0 ? void 0 : _a[obj[globalJoinableTables[table]]];
|
|
45
|
+
return (_b = resolvePath(joinedRecord, path)) !== null && _b !== void 0 ? _b : '~ ?';
|
|
42
46
|
}
|
|
43
47
|
const lower = (s) => s.toLowerCase();
|
|
44
48
|
const upper = (s) => s.toUpperCase();
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/articleStatus.ts
CHANGED
|
@@ -97,13 +97,18 @@ let globalNrAggegationExpressions = 0 // tracks the # aggregations rows so we ca
|
|
|
97
97
|
* The propFunction for FiltreX needs some data that can't be passed as parameters. That's why the 'globalsRelations' variable is needed.
|
|
98
98
|
* TODO: Functional: Experiment with curried functions
|
|
99
99
|
*/
|
|
100
|
+
function resolvePath(obj: Record<string, any> | undefined, path: string[]): any {
|
|
101
|
+
return path.reduce((o, key) => o?.[key], obj)
|
|
102
|
+
}
|
|
103
|
+
|
|
100
104
|
function propFunction(propertyName: string, getPropertyName: Function, obj: Record<string, any>): any {
|
|
101
105
|
const positionOfDot = propertyName.indexOf('.')
|
|
102
106
|
if (positionOfDot < 0) return obj[propertyName]
|
|
103
107
|
const table = propertyName.substring(0, positionOfDot)
|
|
104
|
-
const
|
|
105
|
-
if (table == 'transaction') return obj
|
|
106
|
-
|
|
108
|
+
const path = propertyName.substring(positionOfDot + 1).split('.')
|
|
109
|
+
if (table == 'transaction') return resolvePath(obj, path)
|
|
110
|
+
const joinedRecord = globalRelations[table]?.[obj[globalJoinableTables[table]]]
|
|
111
|
+
return resolvePath(joinedRecord, path) ?? '~ ?'
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
const lower = (s: string) => s.toLowerCase()
|
package/src/types.ts
CHANGED
|
@@ -271,6 +271,61 @@ describe('articleStatus', () => {
|
|
|
271
271
|
expect(result[2].vector[articleStatus.MARGIN]).toBe(50)
|
|
272
272
|
})
|
|
273
273
|
|
|
274
|
+
it('should resolve nested property paths like customer.invoiceAddress.countrycode when grouping', () => {
|
|
275
|
+
const CUSTOMERS = {
|
|
276
|
+
'*zBXU': { invoiceAddress: { countrycode: 'NL' } },
|
|
277
|
+
}
|
|
278
|
+
const rawAggregations = {}
|
|
279
|
+
articleStatus.runQuery(
|
|
280
|
+
{ beginTimeStamp: 1569316408000, endTimeStamp: 1569316409000 + msYear },
|
|
281
|
+
rawAggregations,
|
|
282
|
+
true,
|
|
283
|
+
TRANSACTIONS,
|
|
284
|
+
['customer.invoiceAddress.countrycode'],
|
|
285
|
+
SKUS,
|
|
286
|
+
{},
|
|
287
|
+
CUSTOMERS,
|
|
288
|
+
false,
|
|
289
|
+
'',
|
|
290
|
+
false
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
// Sales (custnr '*zBXU') resolve the nested path to 'NL',
|
|
294
|
+
// beginStock transactions have no custnr and fall back to '~ ?'
|
|
295
|
+
expect(Object.keys(rawAggregations)).toEqual(['** TOTAL **', '~ ?', 'NL'])
|
|
296
|
+
expect(rawAggregations['NL'][articleStatus.QTY_SOLD]).toBe(2)
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
it('should resolve nested property paths in filter expressions', () => {
|
|
300
|
+
const CUSTOMERS = {
|
|
301
|
+
'*zBXU': { invoiceAddress: { countrycode: 'NL' } },
|
|
302
|
+
}
|
|
303
|
+
const run = (countrycode) => {
|
|
304
|
+
const rawAggregations = {}
|
|
305
|
+
articleStatus.runQuery(
|
|
306
|
+
{ beginTimeStamp: 1569316408000, endTimeStamp: 1569316409000 + msYear },
|
|
307
|
+
rawAggregations,
|
|
308
|
+
false,
|
|
309
|
+
TRANSACTIONS,
|
|
310
|
+
['transaction.ean'],
|
|
311
|
+
SKUS,
|
|
312
|
+
{},
|
|
313
|
+
CUSTOMERS,
|
|
314
|
+
false,
|
|
315
|
+
'customer.invoiceAddress.countrycode == "' + countrycode + '"',
|
|
316
|
+
false
|
|
317
|
+
)
|
|
318
|
+
return rawAggregations
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const matching = run('NL')
|
|
322
|
+
expect(Object.keys(matching)).toEqual(['** TOTAL **', '000558000143', '8700558000143'])
|
|
323
|
+
expect(matching['000558000143'][articleStatus.QTY_SOLD]).toBe(1)
|
|
324
|
+
|
|
325
|
+
const nonMatching = run('DE')
|
|
326
|
+
expect(Object.keys(nonMatching)).toEqual([])
|
|
327
|
+
})
|
|
328
|
+
|
|
274
329
|
it('should calculate shelfStock correctly with type 10 (beginShelfStock) and type 94 (picklist)', () => {
|
|
275
330
|
// Test scenario:
|
|
276
331
|
// - beginStock (type 0): 100 units
|