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