@autofleet/sadot 0.6.8-beta.1 → 0.6.8-beta.2
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/scopes/filter.js +13 -15
- package/dist/utils/helpers/index.js +1 -1
- package/package.json +1 -1
- package/src/scopes/filter.ts +13 -15
- package/src/utils/helpers/index.ts +1 -1
package/dist/scopes/filter.js
CHANGED
|
@@ -25,14 +25,13 @@ const customFieldsFilterScope = (name) => (conditions) => {
|
|
|
25
25
|
if (!conditions || Object.keys(conditions).length === 0) {
|
|
26
26
|
return {};
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
const replacementMapPrefix = `customFieldsFilterScopeConditionMap_${randomStr}`;
|
|
28
|
+
const ConditionNameRandomStr = (0, helpers_1.generateRandomString)();
|
|
30
29
|
const replacements = {};
|
|
31
|
-
replacements[
|
|
30
|
+
replacements[ConditionNameRandomStr] = `${name}`;
|
|
32
31
|
// Build the WHERE clause for custom field filtering
|
|
33
32
|
const conditionsStrings = Object.entries(conditions)
|
|
34
|
-
.map(([key, condition]
|
|
35
|
-
const replacemetKey =
|
|
33
|
+
.map(([key, condition]) => {
|
|
34
|
+
const replacemetKey = (0, helpers_1.generateRandomString)();
|
|
36
35
|
replacements[replacemetKey] = `${key}`;
|
|
37
36
|
if (Array.isArray(condition)) {
|
|
38
37
|
if (condition.length === 0) {
|
|
@@ -48,19 +47,19 @@ const customFieldsFilterScope = (name) => (conditions) => {
|
|
|
48
47
|
return `(custom_fields->> :${replacemetKey} ) IN ( ${values} )`;
|
|
49
48
|
}
|
|
50
49
|
return condition
|
|
51
|
-
.map((c
|
|
52
|
-
const valRep =
|
|
50
|
+
.map((c) => {
|
|
51
|
+
const valRep = (0, helpers_1.generateRandomString)();
|
|
53
52
|
replacements[valRep] = `${c.value}`;
|
|
54
53
|
return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} :${valRep}`;
|
|
55
54
|
}).join(AND_DELIMETER);
|
|
56
55
|
}
|
|
57
56
|
if (typeof condition === 'string') {
|
|
58
|
-
const conditionRep =
|
|
57
|
+
const conditionRep = (0, helpers_1.generateRandomString)();
|
|
59
58
|
replacements[conditionRep] = `${condition}`;
|
|
60
59
|
return `(custom_fields->> :${replacemetKey} ) ${castIfNeeded(condition)} = :${conditionRep}`;
|
|
61
60
|
}
|
|
62
61
|
if (condition?.operator) {
|
|
63
|
-
const valueRep =
|
|
62
|
+
const valueRep = (0, helpers_1.generateRandomString)();
|
|
64
63
|
replacements[valueRep] = `${condition.value}`;
|
|
65
64
|
return `(custom_fields->> :${replacemetKey} ) ${castIfNeeded(condition.value)} ${condition.operator} :${valueRep}`;
|
|
66
65
|
}
|
|
@@ -75,7 +74,7 @@ const customFieldsFilterScope = (name) => (conditions) => {
|
|
|
75
74
|
+ 'SELECT cv.model_id, jsonb_object_agg(cd.name, cv.value) AS custom_fields '
|
|
76
75
|
+ 'FROM custom_field_values AS cv '
|
|
77
76
|
+ 'INNER JOIN custom_field_definitions AS cd ON cv.custom_field_definition_id = cd.id '
|
|
78
|
-
+ `AND cd.model_type = :${
|
|
77
|
+
+ `AND cd.model_type = :${ConditionNameRandomStr} `
|
|
79
78
|
+ 'GROUP BY cv.model_id'
|
|
80
79
|
+ ') AS CustomFieldAggregation WHERE '} ${customFieldConditions}`;
|
|
81
80
|
return {
|
|
@@ -95,10 +94,9 @@ const customFieldsSortScope = (name) => (sort) => {
|
|
|
95
94
|
}
|
|
96
95
|
const randomStr = (0, helpers_1.generateRandomString)();
|
|
97
96
|
const replacements = {};
|
|
98
|
-
const includes = Object.entries(sort).map(([key]
|
|
99
|
-
const
|
|
100
|
-
replacements[
|
|
101
|
-
replacements[keyReplacement] = `${key}`;
|
|
97
|
+
const includes = Object.entries(sort).map(([key]) => {
|
|
98
|
+
const keyRandomReplacement = (0, helpers_1.generateRandomString)();
|
|
99
|
+
replacements[keyRandomReplacement] = `${key}`;
|
|
102
100
|
return ([
|
|
103
101
|
sequelize_typescript_1.Sequelize.literal(`(
|
|
104
102
|
SELECT value
|
|
@@ -107,7 +105,7 @@ const customFieldsSortScope = (name) => (sort) => {
|
|
|
107
105
|
ON cv.custom_field_definition_id = cd.id
|
|
108
106
|
AND cd.model_type = '${name}'
|
|
109
107
|
WHERE cv.model_id = "${name}"."id"
|
|
110
|
-
AND cd.name = :${
|
|
108
|
+
AND cd.name = :${keyRandomReplacement}
|
|
111
109
|
) AS CustomFieldAggregation
|
|
112
110
|
)
|
|
113
111
|
`), randomStr,
|
|
@@ -6,7 +6,7 @@ const sequelize_1 = require("sequelize");
|
|
|
6
6
|
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
7
7
|
const constants_1 = require("../constants");
|
|
8
8
|
const generateRandomString = (length = 5) => {
|
|
9
|
-
const characters = '
|
|
9
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
10
10
|
return Array.from({ length }, () => characters.charAt(Math.floor(Math.random() * characters.length))).join('');
|
|
11
11
|
};
|
|
12
12
|
exports.generateRandomString = generateRandomString;
|
package/package.json
CHANGED
package/src/scopes/filter.ts
CHANGED
|
@@ -44,16 +44,15 @@ export const customFieldsFilterScope = (
|
|
|
44
44
|
if (!conditions || Object.keys(conditions).length === 0) {
|
|
45
45
|
return {};
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
const replacementMapPrefix = `customFieldsFilterScopeConditionMap_${randomStr}`;
|
|
47
|
+
const ConditionNameRandomStr = generateRandomString();
|
|
49
48
|
const replacements: Record<string, string> = {};
|
|
50
|
-
replacements[
|
|
49
|
+
replacements[ConditionNameRandomStr] = `${name}`;
|
|
51
50
|
|
|
52
51
|
// Build the WHERE clause for custom field filtering
|
|
53
52
|
const conditionsStrings = Object.entries(conditions)
|
|
54
53
|
.map(
|
|
55
|
-
([key, condition]
|
|
56
|
-
const replacemetKey =
|
|
54
|
+
([key, condition]) => {
|
|
55
|
+
const replacemetKey = generateRandomString();
|
|
57
56
|
replacements[replacemetKey] = `${key}`;
|
|
58
57
|
if (Array.isArray(condition)) {
|
|
59
58
|
if (condition.length === 0) {
|
|
@@ -69,19 +68,19 @@ export const customFieldsFilterScope = (
|
|
|
69
68
|
return `(custom_fields->> :${replacemetKey} ) IN ( ${values} )`;
|
|
70
69
|
}
|
|
71
70
|
return condition
|
|
72
|
-
.map((c
|
|
73
|
-
const valRep =
|
|
71
|
+
.map((c) => {
|
|
72
|
+
const valRep = generateRandomString();
|
|
74
73
|
replacements[valRep] = `${c.value}`;
|
|
75
74
|
return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} :${valRep}`;
|
|
76
75
|
}).join(AND_DELIMETER);
|
|
77
76
|
}
|
|
78
77
|
if (typeof condition === 'string') {
|
|
79
|
-
const conditionRep =
|
|
78
|
+
const conditionRep = generateRandomString();
|
|
80
79
|
replacements[conditionRep] = `${condition}`;
|
|
81
80
|
return `(custom_fields->> :${replacemetKey} ) ${castIfNeeded(condition)} = :${conditionRep}`;
|
|
82
81
|
}
|
|
83
82
|
if (condition?.operator) {
|
|
84
|
-
const valueRep =
|
|
83
|
+
const valueRep = generateRandomString();
|
|
85
84
|
replacements[valueRep] = `${condition.value}`;
|
|
86
85
|
return `(custom_fields->> :${replacemetKey} ) ${castIfNeeded(condition.value)} ${condition.operator} :${valueRep}`;
|
|
87
86
|
}
|
|
@@ -98,7 +97,7 @@ export const customFieldsFilterScope = (
|
|
|
98
97
|
+ 'SELECT cv.model_id, jsonb_object_agg(cd.name, cv.value) AS custom_fields '
|
|
99
98
|
+ 'FROM custom_field_values AS cv '
|
|
100
99
|
+ 'INNER JOIN custom_field_definitions AS cd ON cv.custom_field_definition_id = cd.id '
|
|
101
|
-
+ `AND cd.model_type = :${
|
|
100
|
+
+ `AND cd.model_type = :${ConditionNameRandomStr} `
|
|
102
101
|
+ 'GROUP BY cv.model_id'
|
|
103
102
|
+ ') AS CustomFieldAggregation WHERE '} ${customFieldConditions}`;
|
|
104
103
|
return {
|
|
@@ -121,10 +120,9 @@ export const customFieldsSortScope = (
|
|
|
121
120
|
}
|
|
122
121
|
const randomStr = generateRandomString();
|
|
123
122
|
const replacements: Record<string, string> = {};
|
|
124
|
-
const includes = Object.entries(sort).map(([key]
|
|
125
|
-
const
|
|
126
|
-
replacements[
|
|
127
|
-
replacements[keyReplacement] = `${key}`;
|
|
123
|
+
const includes = Object.entries(sort).map(([key]) => {
|
|
124
|
+
const keyRandomReplacement = generateRandomString();
|
|
125
|
+
replacements[keyRandomReplacement] = `${key}`;
|
|
128
126
|
return ([
|
|
129
127
|
Sequelize.literal(`(
|
|
130
128
|
SELECT value
|
|
@@ -133,7 +131,7 @@ export const customFieldsSortScope = (
|
|
|
133
131
|
ON cv.custom_field_definition_id = cd.id
|
|
134
132
|
AND cd.model_type = '${name}'
|
|
135
133
|
WHERE cv.model_id = "${name}"."id"
|
|
136
|
-
AND cd.name = :${
|
|
134
|
+
AND cd.name = :${keyRandomReplacement}
|
|
137
135
|
) AS CustomFieldAggregation
|
|
138
136
|
)
|
|
139
137
|
`), randomStr,
|
|
@@ -26,7 +26,7 @@ interface CustomFieldsSearchPayload {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export const generateRandomString = (length = 5): string => {
|
|
29
|
-
const characters = '
|
|
29
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
30
30
|
return Array.from({ length }, () => characters.charAt(Math.floor(Math.random() * characters.length))).join('');
|
|
31
31
|
};
|
|
32
32
|
|