@autofleet/sheilta 1.4.0-beta.2 → 1.4.0-beta.2.1
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.d.ts +1 -6
- package/lib/formatter/index.js +31 -27
- package/package.json +1 -1
package/lib/formatter/index.d.ts
CHANGED
|
@@ -16,15 +16,10 @@ export declare type ConditionValue = ConditionWithOperator | ConditionWithOperat
|
|
|
16
16
|
* Generates replacements for the given conditions.
|
|
17
17
|
*
|
|
18
18
|
* @param conditions - The conditions to generate replacements for.
|
|
19
|
+
* @param name - The model type name used to join custom_field_definitions.
|
|
19
20
|
* @returns The replacements object.
|
|
20
21
|
*/
|
|
21
22
|
export declare const generateFilterReplacements: (conditions: Record<string, ConditionValue>) => Record<string, string>;
|
|
22
|
-
/**
|
|
23
|
-
* Generates replacements for the given order array.
|
|
24
|
-
*
|
|
25
|
-
* @param order - The order array to generate replacements for.
|
|
26
|
-
* @returns The replacements object.
|
|
27
|
-
*/
|
|
28
23
|
export declare const generateOrderReplacements: (order: string[]) => Record<string, string>;
|
|
29
24
|
declare const formatPayload: ({ order, page, perPage, include, query, attributes, searchTerm, }: {
|
|
30
25
|
order?: any[];
|
package/lib/formatter/index.js
CHANGED
|
@@ -42,54 +42,52 @@ const getAttributeFromOrder = (order, options = {}) => {
|
|
|
42
42
|
* Generates replacements for the given conditions.
|
|
43
43
|
*
|
|
44
44
|
* @param conditions - The conditions to generate replacements for.
|
|
45
|
+
* @param name - The model type name used to join custom_field_definitions.
|
|
45
46
|
* @returns The replacements object.
|
|
46
47
|
*/
|
|
47
48
|
exports.generateFilterReplacements = (conditions) => {
|
|
48
49
|
const replacements = {};
|
|
50
|
+
console.log('sheilta - conditions:', conditions);
|
|
49
51
|
Object.entries(conditions).forEach(([key, condition]) => {
|
|
50
|
-
const
|
|
51
|
-
replacements[
|
|
52
|
+
const replacemetKey = utils_1.generateRandomString();
|
|
53
|
+
replacements[replacemetKey] = `${key.split(CUSTOM_FIELDS_QUERY_PREFIX)[1]}`;
|
|
52
54
|
if (Array.isArray(condition)) {
|
|
53
55
|
condition.forEach((value) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
if (typeof value === 'string') {
|
|
57
|
+
const valRandom = utils_1.generateRandomString();
|
|
58
|
+
replacements[`${valRandom}`] = `${value}`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const valRep = utils_1.generateRandomString();
|
|
62
|
+
replacements[valRep] = `${value.value}`;
|
|
63
|
+
}
|
|
56
64
|
});
|
|
57
65
|
}
|
|
58
66
|
else if (typeof condition === 'string') {
|
|
59
|
-
const
|
|
60
|
-
replacements[
|
|
67
|
+
const conditionRep = utils_1.generateRandomString();
|
|
68
|
+
replacements[conditionRep] = `${condition}`;
|
|
61
69
|
}
|
|
62
70
|
else if (condition === null || condition === void 0 ? void 0 : condition.operator) {
|
|
63
|
-
const
|
|
64
|
-
replacements[
|
|
71
|
+
const valueRep = utils_1.generateRandomString();
|
|
72
|
+
replacements[valueRep] = `${condition.value}`;
|
|
65
73
|
}
|
|
66
74
|
});
|
|
67
75
|
return replacements;
|
|
68
76
|
};
|
|
69
|
-
/**
|
|
70
|
-
* Generates replacements for the given order array.
|
|
71
|
-
*
|
|
72
|
-
* @param order - The order array to generate replacements for.
|
|
73
|
-
* @returns The replacements object.
|
|
74
|
-
*/
|
|
75
77
|
exports.generateOrderReplacements = (order) => {
|
|
76
78
|
const replacementMap = {};
|
|
77
|
-
order.forEach((
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
order.forEach((o) => {
|
|
80
|
+
if (o.startsWith(CUSTOM_FIELDS_QUERY_PREFIX)) {
|
|
81
|
+
const rand = utils_1.generateRandomString();
|
|
82
|
+
replacementMap[o.split(CUSTOM_FIELDS_QUERY_PREFIX)[1]] = rand;
|
|
83
|
+
}
|
|
84
|
+
else if (o.substring(1).startsWith(CUSTOM_FIELDS_QUERY_PREFIX)) {
|
|
85
|
+
const rand = utils_1.generateRandomString();
|
|
86
|
+
replacementMap[o.substring(1).split(CUSTOM_FIELDS_QUERY_PREFIX)[1]] = rand;
|
|
87
|
+
}
|
|
83
88
|
});
|
|
84
89
|
return replacementMap;
|
|
85
90
|
};
|
|
86
|
-
/**
|
|
87
|
-
* Creates a combined replacement map from order and query.
|
|
88
|
-
*
|
|
89
|
-
* @param order - The order array.
|
|
90
|
-
* @param query - The query object.
|
|
91
|
-
* @returns The combined replacements object.
|
|
92
|
-
*/
|
|
93
91
|
const createReplacementMap = (order, query) => (Object.assign(Object.assign({}, exports.generateOrderReplacements(order)), exports.generateFilterReplacements(query)));
|
|
94
92
|
const formatOrder = ({ order, associationModels = [], replacementsMap = {}, }) => {
|
|
95
93
|
const formattedOrders = [];
|
|
@@ -217,6 +215,12 @@ const formatPayload = ({ order = [], page = utils_1.PAGE_DEFAULT, perPage = util
|
|
|
217
215
|
],
|
|
218
216
|
};
|
|
219
217
|
}
|
|
218
|
+
console.log('🐶');
|
|
219
|
+
console.log('scopes:', [...orderScopes, ...queryScopes]);
|
|
220
|
+
[...orderScopes, ...queryScopes].map((scope) => {
|
|
221
|
+
console.log('scope:', scope.method[0]);
|
|
222
|
+
console.log('scope:', scope.method[1]);
|
|
223
|
+
});
|
|
220
224
|
return Object.assign({ query: formattedQuery, order: filteredFormattedOrder, page: formattedPage, perPage: formattedPerPage, include: formattedInclude, scopes: [...queryScopes, ...orderScopes] }, (formattedAttribute && { attributes: formattedAttribute }));
|
|
221
225
|
};
|
|
222
226
|
exports.default = formatPayload;
|