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