@autofleet/sadot 0.6.8-beta.3 → 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.
@@ -5,15 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.customFieldsSortScope = exports.scopeName = exports.customFieldsFilterScope = void 0;
7
7
  /* eslint-disable import/prefer-default-export */
8
- // eslint-disable-next-line import/no-extraneous-dependencies
9
- const dayjs_1 = __importDefault(require("dayjs"));
10
8
  const sequelize_1 = require("sequelize");
11
9
  const sequelize_typescript_1 = require("sequelize-typescript");
12
10
  const common_types_1 = require("@autofleet/common-types");
11
+ const moment_1 = __importDefault(require("moment"));
13
12
  const helpers_1 = require("../utils/helpers");
14
13
  const { CUSTOM_FIELDS_FILTER_SCOPE } = common_types_1.customFields;
15
14
  const castIfNeeded = (conditionValue) => {
16
- if ((0, dayjs_1.default)(conditionValue).isValid()) {
15
+ if (moment_1.default.isDate(conditionValue)) {
17
16
  return '::timestamp';
18
17
  }
19
18
  if (!Number.isNaN(Number(conditionValue))) {
@@ -39,6 +38,7 @@ const customFieldsFilterScope = (name) => (conditions) => {
39
38
  // Build the WHERE clause for custom field filtering
40
39
  const conditionsStrings = Object.entries(conditions)
41
40
  .map(([key, condition]) => {
41
+ console.log('[sadot] conditions', { key, condition });
42
42
  const replacemetKey = (0, helpers_1.generateRandomString)();
43
43
  replacements[replacemetKey] = `${key}`;
44
44
  if (Array.isArray(condition)) {
@@ -47,6 +47,7 @@ const customFieldsFilterScope = (name) => (conditions) => {
47
47
  return false;
48
48
  }
49
49
  if (typeof condition[0] === 'string') {
50
+ console.log('[sadot] condition[0] === string', { condition });
50
51
  const values = condition.map((v) => {
51
52
  const valRandom = (0, helpers_1.generateRandomString)();
52
53
  replacements[`${valRandom}`] = `${v}`;
@@ -57,9 +58,16 @@ const customFieldsFilterScope = (name) => (conditions) => {
57
58
  return condition
58
59
  .map((c) => {
59
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
+ }
60
67
  replacements[valRep] = `${c.value}`;
61
- return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} :${valRep}`;
62
- }).join(AND_DELIMETER);
68
+ return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} (:${valRep})`;
69
+ })
70
+ .join(AND_DELIMETER);
63
71
  }
64
72
  if (typeof condition === 'string') {
65
73
  const conditionRep = (0, helpers_1.generateRandomString)();
@@ -74,6 +82,7 @@ const customFieldsFilterScope = (name) => (conditions) => {
74
82
  return false;
75
83
  })
76
84
  .filter(Boolean);
85
+ console.log('[sadot] earl ruteurn', { conditionsStrings });
77
86
  if (conditionsStrings.length === 0) {
78
87
  return {};
79
88
  }
@@ -85,6 +94,7 @@ const customFieldsFilterScope = (name) => (conditions) => {
85
94
  + `AND cd.model_type = :${ConditionNameRandomStr} `
86
95
  + 'GROUP BY cv.model_id'
87
96
  + ') AS CustomFieldAggregation WHERE '} ${customFieldConditions}`;
97
+ console.log('[sadot]', { subQuery });
88
98
  return {
89
99
  where: {
90
100
  id: {
@@ -10,10 +10,7 @@ declare const _default: {
10
10
  underscored: boolean;
11
11
  underscoredAll: boolean;
12
12
  };
13
- logging: {
14
- (...data: any[]): void;
15
- (message?: any, ...optionalParams: any[]): void;
16
- };
13
+ logging: boolean;
17
14
  };
18
15
  };
19
16
  export default _default;
@@ -12,6 +12,6 @@ exports.default = {
12
12
  underscored: true,
13
13
  underscoredAll: true,
14
14
  },
15
- logging: console.log,
15
+ logging: false,
16
16
  },
17
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "0.6.8-beta.3",
3
+ "version": "0.6.9-beta.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -34,9 +34,9 @@
34
34
  "@autofleet/errors": "^1.0.10",
35
35
  "@autofleet/events": "^2.0.0",
36
36
  "@autofleet/logger": "^2.0.5",
37
- "dayjs": "^1.11.11",
38
37
  "express": "^4.18.2",
39
38
  "joi": "^17.7.0",
39
+ "moment": "^2.30.1",
40
40
  "pg": "^8.10.0",
41
41
  "reflect-metadata": "^0.1.13",
42
42
  "sequelize": "^6.31.1",
@@ -1,9 +1,8 @@
1
1
  /* eslint-disable import/prefer-default-export */
2
- // eslint-disable-next-line import/no-extraneous-dependencies
3
- import dayjs from 'dayjs';
4
2
  import { Op, type WhereOptions } from 'sequelize';
5
3
  import { Sequelize } from 'sequelize-typescript';
6
4
  import { customFields } from '@autofleet/common-types';
5
+ import moment from 'moment';
7
6
  import { generateRandomString } from '../utils/helpers';
8
7
 
9
8
  const { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;
@@ -30,14 +29,13 @@ export type CustomFieldFilterOptions = {
30
29
  }
31
30
 
32
31
  const castIfNeeded = (conditionValue: string): string => {
33
- if (dayjs(conditionValue).isValid()) {
32
+ if (moment.isDate(conditionValue)) {
34
33
  return '::timestamp';
35
34
  } if (!Number.isNaN(Number(conditionValue))) {
36
35
  return '::numeric';
37
36
  }
38
37
  return '';
39
38
  };
40
-
41
39
  const AND_DELIMETER = ' AND ';
42
40
 
43
41
  /**
@@ -61,6 +59,7 @@ export const customFieldsFilterScope = (
61
59
  const conditionsStrings = Object.entries(conditions)
62
60
  .map(
63
61
  ([key, condition]) => {
62
+ console.log('[sadot] conditions', { key, condition });
64
63
  const replacemetKey = generateRandomString();
65
64
  replacements[replacemetKey] = `${key}`;
66
65
  if (Array.isArray(condition)) {
@@ -69,6 +68,8 @@ export const customFieldsFilterScope = (
69
68
  return false;
70
69
  }
71
70
  if (typeof condition[0] === 'string') {
71
+ console.log('[sadot] condition[0] === string', { condition });
72
+
72
73
  const values = condition.map((v) => {
73
74
  const valRandom = generateRandomString();
74
75
  replacements[`${valRandom}`] = `${v}`;
@@ -79,9 +80,17 @@ export const customFieldsFilterScope = (
79
80
  return condition
80
81
  .map((c) => {
81
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
+ }
82
90
  replacements[valRep] = `${c.value}`;
83
- return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} :${valRep}`;
84
- }).join(AND_DELIMETER);
91
+ return `(custom_fields->> :${replacemetKey} )${castIfNeeded(c.value)} ${c.operator} (:${valRep})`;
92
+ })
93
+ .join(AND_DELIMETER);
85
94
  }
86
95
  if (typeof condition === 'string') {
87
96
  const conditionRep = generateRandomString();
@@ -98,6 +107,8 @@ export const customFieldsFilterScope = (
98
107
  },
99
108
  )
100
109
  .filter(Boolean);
110
+ console.log('[sadot] earl ruteurn', { conditionsStrings });
111
+
101
112
  if (conditionsStrings.length === 0) {
102
113
  return {};
103
114
  }
@@ -109,6 +120,9 @@ export const customFieldsFilterScope = (
109
120
  + `AND cd.model_type = :${ConditionNameRandomStr} `
110
121
  + 'GROUP BY cv.model_id'
111
122
  + ') AS CustomFieldAggregation WHERE '} ${customFieldConditions}`;
123
+
124
+ console.log('[sadot]', { subQuery });
125
+
112
126
  return {
113
127
  where: {
114
128
  id: {
@@ -10,6 +10,6 @@ export default {
10
10
  underscored: true,
11
11
  underscoredAll: true,
12
12
  },
13
- logging: console.log,
13
+ logging: false,
14
14
  },
15
15
  };