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