ti2-ventrata 1.0.4 → 1.0.5
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/index.js +17 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -14,15 +14,22 @@ const isNilOrEmptyArray = el => {
|
|
|
14
14
|
return R.isNil(el) || R.isEmpty(el);
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
const doMap = (obj, map) => {
|
|
17
|
+
const doMap = (obj, map, omitParam = []) => {
|
|
18
18
|
const retVal = {};
|
|
19
|
+
const omit = [
|
|
20
|
+
...omitParam,
|
|
21
|
+
...Object.keys(map),
|
|
22
|
+
];
|
|
19
23
|
Object.entries(map).forEach(([attribute, fn]) => {
|
|
20
24
|
const newVal = fn(obj);
|
|
21
25
|
if (newVal !== undefined) {
|
|
22
26
|
retVal[attribute] = newVal;
|
|
23
27
|
}
|
|
24
28
|
});
|
|
25
|
-
return
|
|
29
|
+
return {
|
|
30
|
+
...retVal,
|
|
31
|
+
...R.omit(omit, obj),
|
|
32
|
+
};
|
|
26
33
|
};
|
|
27
34
|
|
|
28
35
|
const doMapCurry = mapObj => item => doMap(item, mapObj);
|
|
@@ -30,10 +37,13 @@ const doMapCurry = mapObj => item => doMap(item, mapObj);
|
|
|
30
37
|
const productMapIn = {
|
|
31
38
|
productId: R.path(['id']),
|
|
32
39
|
productName: R.path(['title']),
|
|
33
|
-
options: e =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
options: e => R.pathOr(undefined, ['options'], e).map(option => doMap(option, optionMapIn, ['id', 'title'])),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const optionMapIn = {
|
|
44
|
+
optionId: R.path(['id']),
|
|
45
|
+
optionName: R.path(['title']),
|
|
46
|
+
units: option => R.pathOr(undefined, ['units'], option).map(unit => doMap(unit, unitMap)),
|
|
37
47
|
};
|
|
38
48
|
|
|
39
49
|
const rateMap = {
|
|
@@ -68,12 +78,6 @@ const capitalize = sParam => {
|
|
|
68
78
|
return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
|
|
69
79
|
};
|
|
70
80
|
|
|
71
|
-
// const optionMap = {
|
|
72
|
-
// optionId: R.path(['id']),
|
|
73
|
-
// optionName: R.path(['title']),
|
|
74
|
-
// units: option => R.pathOr(undefined, ['units'], option).map(unit => doMap(unit, unitMap)),
|
|
75
|
-
// };
|
|
76
|
-
|
|
77
81
|
const unitMap = {
|
|
78
82
|
unitId: R.path(['id']),
|
|
79
83
|
unitName: R.path(['title']),
|
|
@@ -199,7 +203,7 @@ class Plugin {
|
|
|
199
203
|
headers,
|
|
200
204
|
}));
|
|
201
205
|
if (!Array.isArray(results)) results = [results];
|
|
202
|
-
let products = results.map(e => doMap(e, productMapIn));
|
|
206
|
+
let products = results.map(e => doMap(e, productMapIn, ['id', 'title']));
|
|
203
207
|
// dynamic extra filtering
|
|
204
208
|
if (!isNilOrEmpty(payload)) {
|
|
205
209
|
const extraFilters = R.omit(['productId'], payload);
|