exodus-framework 2.1.1017 → 2.1.1018

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.
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAIzF,eAAO,MAAM,MAAM,WASjB,CAAC;AAuGH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACnF,YAAY,CAAC,CAAC,CAAC,CAwCjB;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,EAClC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,iBAalD"}
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGjE,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEzF,eAAO,MAAM,MAAM,WASjB,CAAC;AAqIH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACnF,YAAY,CAAC,CAAC,CAAC,CAqDjB;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,EAClC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,iBAalD"}
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.InsertIndexes = InsertIndexes;
7
7
  exports.mainDb = void 0;
8
8
  exports.processFilters = processFilters;
9
+ var _dateFns = require("date-fns");
9
10
  var _sequelize = require("sequelize");
10
11
  var _core = _interopRequireDefault(require("../app/core"));
11
12
  var _error = require("../app/error");
12
- var _dateFns = require("date-fns");
13
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
14
  const mainDb = exports.mainDb = new _sequelize.Sequelize({
15
15
  database: _core.default.settings.getDatabase().main.database,
@@ -23,7 +23,7 @@ const mainDb = exports.mainDb = new _sequelize.Sequelize({
23
23
  timezone: '-03:00',
24
24
  logging: _core.default.settings.getDatabase().service.log
25
25
  });
26
- function processCondition(cond) {
26
+ function processCondition(cond, fieldName) {
27
27
  if ('or' in cond) {
28
28
  return {
29
29
  [_sequelize.Op.or]: cond.or.map(subCond => processCondition(subCond))
@@ -51,12 +51,32 @@ function processCondition(cond) {
51
51
  simpleWhere[_sequelize.Op.notBetween] = cond.type === 'DATE' ? cond.notBetween.map(d => new Date(d)) : cond.notBetween;
52
52
  }
53
53
  if (cond.like !== undefined) {
54
- const operator = cond.caseInsensitive ? _sequelize.Op.iLike : _sequelize.Op.like;
55
- simpleWhere[operator] = cond.type === 'DATE' ? new Date(cond.like) : cond.like;
54
+ const value = cond.type === 'DATE' ? new Date(cond.like) : cond.like;
55
+ if (cond.caseInsensitive && fieldName) {
56
+ const dialect = _core.default.settings.getDatabase().main.dialect;
57
+ if (dialect === 'postgres') {
58
+ simpleWhere[_sequelize.Op.iLike] = value;
59
+ } else {
60
+ // Para MariaDB/MySQL, usamos Sequelize.where com função LOWER
61
+ return _sequelize.Sequelize.where(_sequelize.Sequelize.fn('LOWER', _sequelize.Sequelize.col(fieldName)), _sequelize.Op.like, `${value}`.toLowerCase());
62
+ }
63
+ } else {
64
+ simpleWhere[_sequelize.Op.like] = value;
65
+ }
56
66
  }
57
67
  if (cond.notLike !== undefined) {
58
- const operator = cond.caseInsensitive ? _sequelize.Op.notILike : _sequelize.Op.notLike;
59
- simpleWhere[operator] = cond.type === 'DATE' ? new Date(cond.notLike) : cond.notLike;
68
+ const value = cond.type === 'DATE' ? new Date(cond.notLike) : cond.notLike;
69
+ if (cond.caseInsensitive && fieldName) {
70
+ const dialect = _core.default.settings.getDatabase().main.dialect;
71
+ if (dialect === 'postgres') {
72
+ simpleWhere[_sequelize.Op.notILike] = value;
73
+ } else {
74
+ // Para MariaDB/MySQL, usamos Sequelize.where com função LOWER
75
+ return _sequelize.Sequelize.where(_sequelize.Sequelize.fn('LOWER', _sequelize.Sequelize.col(fieldName)), _sequelize.Op.notLike, `${value}`.toLowerCase());
76
+ }
77
+ } else {
78
+ simpleWhere[_sequelize.Op.notLike] = value;
79
+ }
60
80
  }
61
81
  if (cond.in !== undefined) {
62
82
  simpleWhere[_sequelize.Op.in] = cond.type === 'DATE' ? cond.in.map(d => new Date(d)) : cond.in;
@@ -131,7 +151,7 @@ function processFilters(filters) {
131
151
  for (const c of condition) {
132
152
  const [[key, value]] = Object.entries(c);
133
153
  t.push({
134
- [key]: processCondition(value)
154
+ [key]: processCondition(value, key)
135
155
  });
136
156
  }
137
157
  if (!where[logicalOp]) {
@@ -148,14 +168,23 @@ function processFilters(filters) {
148
168
  const [k, c] = processDateCondition(key, condition);
149
169
  where[k] = c;
150
170
  } else {
151
- const processedCondition = processCondition(condition);
152
- if (where[field]) {
153
- where[field] = {
154
- ...where[field],
155
- ...processedCondition
156
- };
171
+ const processedCondition = processCondition(condition, key);
172
+
173
+ // Se retornar um Sequelize.where (case insensitive para MariaDB), precisamos tratar diferente
174
+ if (processedCondition && typeof processedCondition === 'object' && processedCondition.comparator) {
175
+ // É um Sequelize.where
176
+ where[_sequelize.Op.and] = where[_sequelize.Op.and] || [];
177
+ where[_sequelize.Op.and].push(processedCondition);
157
178
  } else {
158
- where[field] = processedCondition;
179
+ // Condição normal
180
+ if (where[field]) {
181
+ where[field] = {
182
+ ...where[field],
183
+ ...processedCondition
184
+ };
185
+ } else {
186
+ where[field] = processedCondition;
187
+ }
159
188
  }
160
189
  }
161
190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exodus-framework",
3
- "version": "2.1.1017",
3
+ "version": "2.1.1018",
4
4
  "description": "Exodus Framework",
5
5
  "author": "jhownpaixao",
6
6
  "license": "ISC",