ismx-nexo-node-app 0.4.133 → 0.4.135

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.
@@ -81,6 +81,8 @@ class BusinessErrors {
81
81
  getBodyParam(param, body) {
82
82
  let path = param.split(".");
83
83
  let value = body;
84
+ if (value === undefined || value === null)
85
+ this.except("0014", param);
84
86
  for (let key of path) {
85
87
  value = value[key];
86
88
  if (value === undefined || value === null)
package/dist/js/index.js CHANGED
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.RestUtils = exports.QueryUtils = exports.RepositoryRestFormalTemplate = exports.RepositoryRestFormal = exports.RepositoryRest = exports.RepositoryDatabasePostgres = exports.RepositoryDatabase = exports.Repository = exports.PromiseUtils = exports.ArrayUtils = exports.StringUtils = exports.NumberUtils = exports.CryptoUtils = exports.DateUtils = exports.BusinessLogger = exports.FormalError = exports.BusinessErrors = exports.BusinessThreadState = exports.BusinessThread = exports.BusinessServer = exports.FormalLoopbackBusiness = exports.FormalProxyBusiness = exports.ProxyBusiness = exports.BusinessState = exports.Business = exports.ColorUtils = exports.ServiceRestFormalTemplate = exports.ServiceRestFormal = exports.ServiceRest = exports.HttpResponse = exports.Service = void 0;
29
+ exports.PostgresUtils = exports.RestUtils = exports.QueryUtils = exports.RepositoryRestFormalTemplate = exports.RepositoryRestFormal = exports.RepositoryRest = exports.RepositoryDatabasePostgres = exports.RepositoryDatabase = exports.Repository = exports.PromiseUtils = exports.ArrayUtils = exports.StringUtils = exports.NumberUtils = exports.CryptoUtils = exports.DateUtils = exports.BusinessLogger = exports.FormalError = exports.BusinessErrors = exports.BusinessThreadState = exports.BusinessThread = exports.BusinessServer = exports.FormalLoopbackBusiness = exports.FormalProxyBusiness = exports.ProxyBusiness = exports.BusinessState = exports.Business = exports.ColorUtils = exports.ServiceRestFormalTemplate = exports.ServiceRestFormal = exports.ServiceRest = exports.HttpResponse = exports.Service = void 0;
30
30
  const Service_1 = __importStar(require("./api/Service"));
31
31
  class Service extends Service_1.default {
32
32
  }
@@ -151,3 +151,7 @@ const RestUtils_1 = __importDefault(require("./repository/utils/RestUtils"));
151
151
  class RestUtils extends RestUtils_1.default {
152
152
  }
153
153
  exports.RestUtils = RestUtils;
154
+ const PostgresUtils_1 = __importDefault(require("./repository/utils/PostgresUtils"));
155
+ class PostgresUtils extends PostgresUtils_1.default {
156
+ }
157
+ exports.PostgresUtils = PostgresUtils;
@@ -35,9 +35,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.PgOperator = void 0;
38
39
  const PostgresUtils_1 = __importDefault(require("./utils/PostgresUtils"));
39
40
  const RepositoryDatabase_1 = __importDefault(require("./RepositoryDatabase"));
40
41
  const Repository_1 = require("./Repository");
42
+ class PgOperator {
43
+ constructor(vals, toWhere) {
44
+ this.toWhere = toWhere;
45
+ this.vals = vals;
46
+ }
47
+ }
48
+ exports.PgOperator = PgOperator;
41
49
  class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
42
50
  constructor() {
43
51
  super();
@@ -270,14 +278,22 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
270
278
  continue;
271
279
  if (alias !== "")
272
280
  alias += ".";
273
- if (value instanceof Array)
281
+ if (value instanceof Array) {
274
282
  where += ` AND ${alias}${column} = ANY(\$${iter++})`;
275
- else if (value === null)
283
+ values.push(value);
284
+ }
285
+ else if (value instanceof PgOperator) {
286
+ let idxs = value.vals.map((v) => `\$${iter++}`);
287
+ where += ` AND ${value.toWhere(`${alias}${column}`, idxs)}`;
288
+ values.push(...value.vals);
289
+ }
290
+ else if (value === null) {
276
291
  where += ` AND ${alias}${column} IS NULL`;
277
- else
278
- where += ` AND ${alias}${column}=\$${iter++}`;
279
- if (value !== null)
292
+ }
293
+ else {
294
+ where += ` AND ${alias}${column} = \$${iter++}`;
280
295
  values.push(value);
296
+ }
281
297
  }
282
298
  return { where, values };
283
299
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const RepositoryDatabasePostgres_1 = require("../RepositoryDatabasePostgres");
3
4
  class PostgresUtils {
4
5
  static camelToSnake(column) {
5
6
  return column.replace(/([A-Z])/g, '_$1').toLowerCase();
@@ -53,5 +54,8 @@ class PostgresUtils {
53
54
  result[key] = value;
54
55
  return result;
55
56
  }
57
+ static op(vals, toWhere) {
58
+ return new RepositoryDatabasePostgres_1.PgOperator(vals, toWhere);
59
+ }
56
60
  }
57
61
  exports.default = PostgresUtils;
@@ -103,3 +103,6 @@ export declare abstract class QueryUtils extends _QueryUtils {
103
103
  import _RestUtils from "./repository/utils/RestUtils";
104
104
  export declare abstract class RestUtils extends _RestUtils {
105
105
  }
106
+ import _PostgresUtils from "./repository/utils/PostgresUtils";
107
+ export declare abstract class PostgresUtils extends _PostgresUtils {
108
+ }
@@ -5,6 +5,11 @@ export interface Column {
5
5
  schema: string;
6
6
  default?: string;
7
7
  }
8
+ export declare class PgOperator {
9
+ readonly toWhere: (column: string, params: string[]) => string;
10
+ readonly vals: Valuable[];
11
+ constructor(vals: Valuable[], toWhere: (column: string, params: string[]) => string);
12
+ }
8
13
  export default class RepositoryDatabasePostgres extends RepositoryDatabase {
9
14
  private readonly introspectIntervalTime;
10
15
  protected client: any;
@@ -56,10 +61,10 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
56
61
  runTable<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<T[]>;
57
62
  runValue<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<Valuable | undefined>;
58
63
  toWhere(tableName: string, filters?: {
59
- [key: string]: Valuable | Array<Valuable>;
64
+ [key: string]: Valuable | Array<Valuable> | PgOperator;
60
65
  }, alias?: string, index?: number): {
61
66
  where: string;
62
- values: (string | number | symbol | Date | Valuable[])[];
67
+ values: (string | number | symbol | Date | Valuable[] | null | undefined)[];
63
68
  };
64
69
  anyWhere(filters: any, alias?: string, index?: number): {
65
70
  where: string;
@@ -1,4 +1,4 @@
1
- import { Column } from "../RepositoryDatabasePostgres";
1
+ import { Column, PgOperator } from "../RepositoryDatabasePostgres";
2
2
  import { Valuable } from "../RepositoryDatabase";
3
3
  export default abstract class PostgresUtils {
4
4
  static camelToSnake(column: string): string;
@@ -15,4 +15,5 @@ export default abstract class PostgresUtils {
15
15
  static fromEntries(iterable: [string, any][]): {
16
16
  [key: string]: any;
17
17
  };
18
+ static op(vals: Valuable[], toWhere: (column: string, params: string[]) => string): PgOperator;
18
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.133",
3
+ "version": "0.4.135",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -79,6 +79,8 @@ export default class BusinessErrors {
79
79
  getBodyParam(param: string, body: any): any {
80
80
  let path = param.split(".");
81
81
  let value = body;
82
+ if (value === undefined || value === null)
83
+ this.except("0014", param);
82
84
  for (let key of path) {
83
85
  value = value[key];
84
86
  if (value === undefined || value === null) this.except("0014", param);
@@ -97,3 +97,6 @@ export abstract class QueryUtils extends _QueryUtils {}
97
97
 
98
98
  import _RestUtils from "./repository/utils/RestUtils";
99
99
  export abstract class RestUtils extends _RestUtils {}
100
+
101
+ import _PostgresUtils from "./repository/utils/PostgresUtils";
102
+ export abstract class PostgresUtils extends _PostgresUtils {}
@@ -8,6 +8,14 @@ export interface Column {
8
8
  default?: string
9
9
  }
10
10
 
11
+ export class PgOperator {
12
+ readonly toWhere: (column: string, params: string[]) => string;
13
+ readonly vals: Valuable[];
14
+ constructor(vals: Valuable[], toWhere: (column: string, params: string[]) => string) {
15
+ this.toWhere = toWhere; this.vals = vals;
16
+ }
17
+ }
18
+
11
19
  export default class RepositoryDatabasePostgres extends RepositoryDatabase
12
20
  {
13
21
  private readonly introspectIntervalTime: number = 60 * 60 * 1000;
@@ -226,7 +234,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
226
234
  return this.run<T>(name, params, filters).then((result) => Object.values(result[0] ?? {})[0] as Valuable)
227
235
  }
228
236
 
229
- toWhere(tableName: string, filters: { [key: string]: Valuable | Array<Valuable> }={}, alias:string = "", index=1)
237
+ toWhere(tableName: string, filters: { [key: string]: Valuable | Array<Valuable> | PgOperator }={}, alias:string = "", index=1)
230
238
  {
231
239
  let table = this.tables[tableName];
232
240
  let columns = PostgresUtils.columns(table);
@@ -236,10 +244,23 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
236
244
  let value = filters[PostgresUtils.snakeToCamel(column.replace(/"/g, ''))]
237
245
  if (value === undefined) continue;
238
246
  if (alias !== "") alias += "."
239
- if (value instanceof Array) where += ` AND ${alias}${column} = ANY(\$${iter++})`
240
- else if (value === null) where += ` AND ${alias}${column} IS NULL`
241
- else where += ` AND ${alias}${column}=\$${iter++}`
242
- if (value !== null) values.push(value);
247
+
248
+ if (value instanceof Array) {
249
+ where += ` AND ${alias}${column} = ANY(\$${iter++})`;
250
+ values.push(value);
251
+
252
+ } else if (value instanceof PgOperator) {
253
+ let idxs = value.vals.map((v) => `\$${iter++}`)
254
+ where += ` AND ${value.toWhere(`${alias}${column}`, idxs)}`
255
+ values.push(...value.vals);
256
+
257
+ } else if (value === null) {
258
+ where += ` AND ${alias}${column} IS NULL`
259
+
260
+ } else {
261
+ where += ` AND ${alias}${column} = \$${iter++}`;
262
+ values.push(value);
263
+ }
243
264
  }
244
265
 
245
266
  return { where, values };
@@ -1,4 +1,4 @@
1
- import {Column} from "../RepositoryDatabasePostgres";
1
+ import {Column, PgOperator} from "../RepositoryDatabasePostgres";
2
2
  import {Valuable} from "../RepositoryDatabase";
3
3
 
4
4
  export default abstract class PostgresUtils
@@ -68,4 +68,8 @@ export default abstract class PostgresUtils
68
68
  result[key] = value;
69
69
  return result;
70
70
  }
71
+
72
+ static op(vals: Valuable[], toWhere: (column: string, params: string[]) => string): PgOperator {
73
+ return new PgOperator(vals, toWhere);
74
+ }
71
75
  }