@autofleet/sadot 0.6.9-beta.1 → 0.6.9
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 +2 -13
- package/package.json +1 -1
- package/src/scopes/filter.ts +2 -19
package/dist/scopes/filter.js
CHANGED
|
@@ -38,17 +38,14 @@ const customFieldsFilterScope = (name) => (conditions) => {
|
|
|
38
38
|
// Build the WHERE clause for custom field filtering
|
|
39
39
|
const conditionsStrings = Object.entries(conditions)
|
|
40
40
|
.map(([key, condition]) => {
|
|
41
|
-
console.log('[sadot] conditions', { key, condition });
|
|
42
41
|
const replacemetKey = (0, helpers_1.generateRandomString)();
|
|
43
42
|
replacements[replacemetKey] = `${key}`;
|
|
44
43
|
if (Array.isArray(condition)) {
|
|
45
|
-
console.log('[sadot] Array.isArray(condition)', { condition });
|
|
46
44
|
if (condition.length === 0) {
|
|
47
45
|
// if empty array, the condition is ignored
|
|
48
46
|
return false;
|
|
49
47
|
}
|
|
50
48
|
if (typeof condition[0] === 'string') {
|
|
51
|
-
console.log('[sadot] condition[0] === string', { condition });
|
|
52
49
|
const values = condition.map((v) => {
|
|
53
50
|
const valRandom = (0, helpers_1.generateRandomString)();
|
|
54
51
|
replacements[`${valRandom}`] = `${v}`;
|
|
@@ -59,15 +56,9 @@ const customFieldsFilterScope = (name) => (conditions) => {
|
|
|
59
56
|
return condition
|
|
60
57
|
.map((c) => {
|
|
61
58
|
const valRep = (0, helpers_1.generateRandomString)();
|
|
62
|
-
if (c.operator.toUpperCase() === 'IN' && Array.isArray(c.value)) {
|
|
63
|
-
const formattedValues = c.value.map((val) => `'${val}'`).join(', ');
|
|
64
|
-
replacements[valRep] = formattedValues;
|
|
65
|
-
return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} (${formattedValues})`;
|
|
66
|
-
}
|
|
67
59
|
replacements[valRep] = `${c.value}`;
|
|
68
|
-
return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator}
|
|
69
|
-
})
|
|
70
|
-
.join(AND_DELIMETER);
|
|
60
|
+
return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} :${valRep}`;
|
|
61
|
+
}).join(AND_DELIMETER);
|
|
71
62
|
}
|
|
72
63
|
if (typeof condition === 'string' || typeof condition === 'number') {
|
|
73
64
|
const conditionRep = (0, helpers_1.generateRandomString)();
|
|
@@ -82,7 +73,6 @@ const customFieldsFilterScope = (name) => (conditions) => {
|
|
|
82
73
|
return false;
|
|
83
74
|
})
|
|
84
75
|
.filter(Boolean);
|
|
85
|
-
console.log('[sadot] earl ruteurn', { conditionsStrings });
|
|
86
76
|
if (conditionsStrings.length === 0) {
|
|
87
77
|
return {};
|
|
88
78
|
}
|
|
@@ -94,7 +84,6 @@ const customFieldsFilterScope = (name) => (conditions) => {
|
|
|
94
84
|
+ `AND cd.model_type = :${ConditionNameRandomStr} `
|
|
95
85
|
+ 'GROUP BY cv.model_id'
|
|
96
86
|
+ ') AS CustomFieldAggregation WHERE '} ${customFieldConditions}`;
|
|
97
|
-
console.log('[sadot]', { subQuery });
|
|
98
87
|
return {
|
|
99
88
|
where: {
|
|
100
89
|
id: {
|
package/package.json
CHANGED
package/src/scopes/filter.ts
CHANGED
|
@@ -59,19 +59,14 @@ export const customFieldsFilterScope = (
|
|
|
59
59
|
const conditionsStrings = Object.entries(conditions)
|
|
60
60
|
.map(
|
|
61
61
|
([key, condition]) => {
|
|
62
|
-
console.log('[sadot] conditions', { key, condition });
|
|
63
62
|
const replacemetKey = generateRandomString();
|
|
64
63
|
replacements[replacemetKey] = `${key}`;
|
|
65
64
|
if (Array.isArray(condition)) {
|
|
66
|
-
console.log('[sadot] Array.isArray(condition)', { condition });
|
|
67
|
-
|
|
68
65
|
if (condition.length === 0) {
|
|
69
66
|
// if empty array, the condition is ignored
|
|
70
67
|
return false;
|
|
71
68
|
}
|
|
72
69
|
if (typeof condition[0] === 'string') {
|
|
73
|
-
console.log('[sadot] condition[0] === string', { condition });
|
|
74
|
-
|
|
75
70
|
const values = condition.map((v) => {
|
|
76
71
|
const valRandom = generateRandomString();
|
|
77
72
|
replacements[`${valRandom}`] = `${v}`;
|
|
@@ -82,16 +77,9 @@ export const customFieldsFilterScope = (
|
|
|
82
77
|
return condition
|
|
83
78
|
.map((c) => {
|
|
84
79
|
const valRep = generateRandomString();
|
|
85
|
-
|
|
86
|
-
if (c.operator.toUpperCase() === 'IN' && Array.isArray(c.value)) {
|
|
87
|
-
const formattedValues = c.value.map((val) => `'${val}'`).join(', ');
|
|
88
|
-
replacements[valRep] = formattedValues;
|
|
89
|
-
return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} (${formattedValues})`;
|
|
90
|
-
}
|
|
91
80
|
replacements[valRep] = `${c.value}`;
|
|
92
|
-
return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator}
|
|
93
|
-
})
|
|
94
|
-
.join(AND_DELIMETER);
|
|
81
|
+
return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} :${valRep}`;
|
|
82
|
+
}).join(AND_DELIMETER);
|
|
95
83
|
}
|
|
96
84
|
if (typeof condition === 'string' || typeof condition === 'number') {
|
|
97
85
|
const conditionRep = generateRandomString();
|
|
@@ -108,8 +96,6 @@ export const customFieldsFilterScope = (
|
|
|
108
96
|
},
|
|
109
97
|
)
|
|
110
98
|
.filter(Boolean);
|
|
111
|
-
console.log('[sadot] earl ruteurn', { conditionsStrings });
|
|
112
|
-
|
|
113
99
|
if (conditionsStrings.length === 0) {
|
|
114
100
|
return {};
|
|
115
101
|
}
|
|
@@ -121,9 +107,6 @@ export const customFieldsFilterScope = (
|
|
|
121
107
|
+ `AND cd.model_type = :${ConditionNameRandomStr} `
|
|
122
108
|
+ 'GROUP BY cv.model_id'
|
|
123
109
|
+ ') AS CustomFieldAggregation WHERE '} ${customFieldConditions}`;
|
|
124
|
-
|
|
125
|
-
console.log('[sadot]', { subQuery });
|
|
126
|
-
|
|
127
110
|
return {
|
|
128
111
|
where: {
|
|
129
112
|
id: {
|