@autofleet/sheilta 1.3.2-6 → 1.3.2-7
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/lib/formatter/index.js
CHANGED
|
@@ -8,14 +8,22 @@ const common_types_1 = require("@autofleet/common-types");
|
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const DEFAULT_ORDER = 'id';
|
|
10
10
|
const DESCENDING_KEY = 'DESC';
|
|
11
|
-
const ASCENDING_KEY = 'ASC';
|
|
11
|
+
/* const ASCENDING_KEY = 'ASC'; */
|
|
12
12
|
const CUSTOM_FIELDS_QUERY_PREFIX = 'customFields.';
|
|
13
13
|
const { CUSTOM_FIELDS_FILTER_SCOPE } = common_types_1.customFields;
|
|
14
14
|
const getAttributeFromOrder = (order, literalAttributes) => {
|
|
15
15
|
const [formattedOrder, attributes] = order.reduce((acc, o) => {
|
|
16
|
-
const [item
|
|
16
|
+
const [item] = Array.isArray(o) ? o : [o];
|
|
17
17
|
const found = literalAttributes === null || literalAttributes === void 0 ? void 0 : literalAttributes.find(obj => obj.attribute === item);
|
|
18
|
-
(found
|
|
18
|
+
if (found) {
|
|
19
|
+
/* const [literal, name = found.attribute] =
|
|
20
|
+
Array.isArray(found.literal) ? found.literal : [found.literal];
|
|
21
|
+
console.log({ found, itemOrder }); */
|
|
22
|
+
acc[1].push(found.literal);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
acc[0].push(o);
|
|
26
|
+
}
|
|
19
27
|
return acc;
|
|
20
28
|
}, [[], []]);
|
|
21
29
|
return [formattedOrder, attributes];
|
|
@@ -190,7 +190,7 @@ describe('formatting test', () => {
|
|
|
190
190
|
expect(JSON.stringify(order)).toBe(JSON.stringify([['status.name', 'DESC'], ['id']]));
|
|
191
191
|
});
|
|
192
192
|
it('by literal field ascending', () => {
|
|
193
|
-
const literalAttribute = { attribute: 'genericField', literal:
|
|
193
|
+
const literalAttribute = { attribute: 'genericField', literal: [{ 0: e => `${e}0` }] };
|
|
194
194
|
const { order, attributes } = _1.default({
|
|
195
195
|
order: [literalAttribute.attribute],
|
|
196
196
|
}, {
|
|
@@ -201,10 +201,12 @@ describe('formatting test', () => {
|
|
|
201
201
|
literalAttributes: [literalAttribute],
|
|
202
202
|
});
|
|
203
203
|
expect(JSON.stringify(order)).toBe(JSON.stringify([['id']]));
|
|
204
|
-
|
|
204
|
+
console.log({ attributes });
|
|
205
|
+
expect(JSON.stringify(attributes))
|
|
206
|
+
.toBe(JSON.stringify({ include: [literalAttribute.literal] }));
|
|
205
207
|
});
|
|
206
208
|
it('by literal field descending', () => {
|
|
207
|
-
const literalAttribute = { attribute: 'genericField', literal: 'void' };
|
|
209
|
+
const literalAttribute = { attribute: 'genericField', literal: ['void', 'field'] };
|
|
208
210
|
const { order, attributes } = _1.default({
|
|
209
211
|
order: [`-${literalAttribute.attribute}`, 'currencySymbol'],
|
|
210
212
|
}, {
|
|
@@ -215,7 +217,8 @@ describe('formatting test', () => {
|
|
|
215
217
|
literalAttributes: [literalAttribute],
|
|
216
218
|
});
|
|
217
219
|
expect(JSON.stringify(order)).toBe(JSON.stringify([['currencySymbol'], ['id']]));
|
|
218
|
-
expect(JSON.stringify(attributes))
|
|
220
|
+
expect(JSON.stringify(attributes))
|
|
221
|
+
.toBe(JSON.stringify({ include: [[literalAttribute.literal[0], literalAttribute.literal[1]]] }));
|
|
219
222
|
});
|
|
220
223
|
it('by literal field - not found', () => {
|
|
221
224
|
const literalAttribute = { attribute: 'genericField', literal: 'void' };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/sheilta",
|
|
3
|
-
"version": "1.3.2-
|
|
3
|
+
"version": "1.3.2-7",
|
|
4
4
|
"description": "manage cache",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@autofleet/common-types": "^1.7.29",
|
|
31
31
|
"@autofleet/errors": "^1.0.10",
|
|
32
|
+
"@autofleet/sheilta": "^1.3.2-6",
|
|
32
33
|
"joi": "^17.9.2",
|
|
33
34
|
"lodash": "^4.17.21"
|
|
34
35
|
},
|
|
@@ -48,4 +49,4 @@
|
|
|
48
49
|
"files": [
|
|
49
50
|
"lib/**/*"
|
|
50
51
|
]
|
|
51
|
-
}
|
|
52
|
+
}
|