test-entity-library-asm 3.9.57 → 3.9.59

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.
@@ -25,5 +25,10 @@ export declare class CustomRepository<T extends ObjectLiteral> extends Repositor
25
25
  getLocalsCompanyInformationForTheTableWrapper(params: IBasicCompany): Promise<{
26
26
  data: any[];
27
27
  totalRecords: number;
28
+ query: [string, any[]];
29
+ } | {
30
+ data: never[];
31
+ totalRecords: number;
32
+ query: null;
28
33
  }>;
29
34
  }
@@ -1,6 +1,11 @@
1
1
  import { Repository } from "typeorm";
2
2
  import { IBasicCompany } from "../interfaces";
3
- export declare function getLocalsCompanyInformationTable(repository: Repository<any>, { company, status, visible, lazyEvent, filter_visualization, }: IBasicCompany): Promise<{
3
+ export declare function getLocalsCompanyInformationTable(repository: Repository<any>, { company, status, visible, lazyEvent }: IBasicCompany): Promise<{
4
4
  data: any[];
5
5
  totalRecords: number;
6
+ query: [string, any[]];
7
+ } | {
8
+ data: never[];
9
+ totalRecords: number;
10
+ query: null;
6
11
  }>;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLocalsCompanyInformationTable = void 0;
4
- async function getLocalsCompanyInformationTable(repository, { company, status, visible, lazyEvent, filter_visualization = 2, // "no-in-review-rejected"
5
- }) {
4
+ async function getLocalsCompanyInformationTable(repository, { company, status, visible, lazyEvent }) {
6
5
  try {
7
6
  const queryBuilder = repository
8
7
  .createQueryBuilder("locals_company_information_for_the_table")
@@ -11,7 +10,7 @@ async function getLocalsCompanyInformationTable(repository, { company, status, v
11
10
  // DOC: Filtro global
12
11
  if (lazyEvent.filters["global"] && lazyEvent.filters["global"].value) {
13
12
  const globalValue = `%${lazyEvent.filters["global"].value.toLowerCase()}%`;
14
- queryBuilder.andWhere("(LOWER(locals_company_information_for_the_table.name) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.address) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_name) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_surname) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_full_name) LIKE :globalValue OR locals_company_information_for_the_table.partner_full_name LIKE :globalValue", { globalValue });
13
+ queryBuilder.andWhere("(LOWER(locals_company_information_for_the_table.code) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.name) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.address) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_name) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_surname) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_full_name) LIKE :globalValue OR locals_company_information_for_the_table.partner_full_name LIKE :globalValue)", { globalValue });
15
14
  }
16
15
  // DOC: Filtro por estado FILTRO POR DEFECTO.
17
16
  if (status !== null && status >= 0) {
@@ -31,17 +30,6 @@ async function getLocalsCompanyInformationTable(repository, { company, status, v
31
30
  visible,
32
31
  });
33
32
  }
34
- // DOC: la columna filter_visualization se utiliza para aplicar el filtro review_status y operation_type.
35
- // DOC: Si filter_visualization es "in-review-rejected", se muestran los locales que están en revisión o rechazados, es decir, review_status = 1 o 3 y operation_type = 1 o 2.
36
- // DOC: Si filter_visualization es "no-in-review-rejected", se muestran los locales que no están en revisión ni rechazados, es decir, review_status es null y operation_type es null.
37
- if (filter_visualization === 1) {
38
- // "in-review-rejected"
39
- queryBuilder.andWhere("(locals_company_information_for_the_table.review_status IN (1, 3) AND locals_company_information_for_the_table.operation_type IN (1, 2))");
40
- }
41
- else if (filter_visualization === 2) {
42
- // "no-in-review-rejected"
43
- queryBuilder.andWhere("(locals_company_information_for_the_table.review_status IS NULL AND locals_company_information_for_the_table.operation_type IS NULL)");
44
- }
45
33
  // DOC: Acá vienen los otros filtros, por las columnas de la tabla.
46
34
  const filters = lazyEvent.filters;
47
35
  Object.keys(filters).forEach((key) => {
@@ -59,6 +47,64 @@ async function getLocalsCompanyInformationTable(repository, { company, status, v
59
47
  : `locals_company_information_for_the_table.${key}`; // DOC: Verificamos si el filtro es un campo anidado o no.
60
48
  switch (matchMode // DOC: Verificamos el modo de coincidencia del filtro.
61
49
  ) {
50
+ case "custom":
51
+ // 📌 Filtro por created / updated (rango de fechas en UTC)
52
+ if (key === "created" || key === "updated") {
53
+ if (Array.isArray(value) && value.length === 2) {
54
+ const [from, to] = value;
55
+ if (from !== null && to === null) {
56
+ queryBuilder.andWhere(`${accessKey} >= :from`, {
57
+ from: new Date(from),
58
+ });
59
+ }
60
+ else if (from === null && to !== null) {
61
+ queryBuilder.andWhere(`${accessKey} <= :to`, {
62
+ to: new Date(to),
63
+ });
64
+ }
65
+ else if (from !== null && to !== null) {
66
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
67
+ from: new Date(from),
68
+ to: new Date(to),
69
+ });
70
+ }
71
+ }
72
+ }
73
+ // 📌 Filtro por created_by (array de ids)
74
+ if (key === "created_by") {
75
+ if (Array.isArray(value) && value.length > 0) {
76
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
77
+ [key]: value,
78
+ });
79
+ }
80
+ }
81
+ // 📌 Filtro por updated_by (array de ids)
82
+ if (key === "updated_by") {
83
+ if (Array.isArray(value) && value.length > 0) {
84
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
85
+ [key]: value,
86
+ });
87
+ }
88
+ }
89
+ // 📌 Filtro por total_requests / average_rating (rango numérico)
90
+ if (key === "total_requests" || key === "average_rating") {
91
+ if (Array.isArray(value) && value.length === 2) {
92
+ const [from, to] = value;
93
+ if (from !== null && to === null) {
94
+ queryBuilder.andWhere(`${accessKey} >= :from`, { from });
95
+ }
96
+ else if (from === null && to !== null) {
97
+ queryBuilder.andWhere(`${accessKey} <= :to`, { to });
98
+ }
99
+ else if (from !== null && to !== null) {
100
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
101
+ from,
102
+ to,
103
+ });
104
+ }
105
+ }
106
+ }
107
+ break;
62
108
  case "contains": // DOC: Si el modo de coincidencia es "contains".
63
109
  queryBuilder.andWhere(`LOWER(${accessKey}) LIKE :${key}`, {
64
110
  [key]: `%${value}%`,
@@ -163,15 +209,21 @@ async function getLocalsCompanyInformationTable(repository, { company, status, v
163
209
  }
164
210
  // DOC: Ejecutamos la consulta y obtenemos los resultados.
165
211
  const [data, totalRecords] = await queryBuilder.getManyAndCount();
212
+ // DOC: Si quieres ver la consulta generada, puedes descomentar las siguientes líneas:
213
+ // console.log("Query:", queryBuilder.getQuery());
214
+ console.log("Query:", queryBuilder.getQueryAndParameters());
166
215
  return {
167
216
  data,
168
217
  totalRecords,
218
+ query: queryBuilder.getQueryAndParameters(),
169
219
  };
170
220
  }
171
221
  catch (error) {
222
+ console.log(error, "error por acá");
172
223
  return {
173
224
  data: [],
174
225
  totalRecords: 0,
226
+ query: null,
175
227
  };
176
228
  }
177
229
  }
package/dist/index.d.ts CHANGED
@@ -33,5 +33,10 @@ export declare const getRepositoryByEntity: <T extends ObjectLiteral>(entity: En
33
33
  getLocalsCompanyInformationForTheTableWrapper(params: IBasicCompany): Promise<{
34
34
  data: any[];
35
35
  totalRecords: number;
36
+ query: [string, any[]];
37
+ } | {
38
+ data: never[];
39
+ totalRecords: number;
40
+ query: null;
36
41
  }>;
37
42
  }>;
package/dist/index.js CHANGED
@@ -15,9 +15,6 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
- };
21
18
  var __importStar = (this && this.__importStar) || function (mod) {
22
19
  if (mod && mod.__esModule) return mod;
23
20
  var result = {};
@@ -25,16 +22,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
22
  __setModuleDefault(result, mod);
26
23
  return result;
27
24
  };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.getRepositoryByEntity = exports.getTimezoneOffset = exports.getTimeZone = exports.timezoneMiddleware = exports.callStoredProcedure = exports.showEntity = exports.showEntityNameEntity = exports.createDataBaseSource = void 0;
30
30
  const async_hooks_1 = require("async_hooks");
31
31
  const dotenv_1 = require("dotenv");
32
32
  const path_1 = require("path");
33
33
  const typeorm_1 = require("typeorm");
34
- const moment = require("moment-timezone");
34
+ const EntitiesViewsRoutes = __importStar(require("./entities.index"));
35
35
  const entities_views_routes_1 = require("./entities.views.routes");
36
+ const moment = require("moment-timezone");
36
37
  __exportStar(require("./entities.views.routes"), exports);
37
- const EntitiesViewsRoutes = __importStar(require("./entities.index"));
38
38
  const asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
39
39
  let connection = null;
40
40
  // DOCUMENTATION: Función para crear la conexión de la base de datos
@@ -28,7 +28,6 @@ export interface IBasicCompany extends IBasicLazyEvent {
28
28
  company: number | null;
29
29
  visible?: number | null;
30
30
  owner?: number | null;
31
- filter_visualization?: number | null;
32
31
  }
33
32
  export interface IPropsQueryVerifyLocalInformation extends IPropsQueryVerifyLocal {
34
33
  partner: number | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "3.9.57",
3
+ "version": "3.9.59",
4
4
  "description": "Entidades de ejemplo para una base de datos",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,15 +1,10 @@
1
1
  import { Repository } from "typeorm";
2
2
  import { IBasicCompany } from "../interfaces";
3
+ import { query } from "express";
3
4
 
4
5
  export async function getLocalsCompanyInformationTable(
5
6
  repository: Repository<any>,
6
- {
7
- company,
8
- status,
9
- visible,
10
- lazyEvent,
11
- filter_visualization = 2, // "no-in-review-rejected"
12
- }: IBasicCompany,
7
+ { company, status, visible, lazyEvent }: IBasicCompany,
13
8
  ) {
14
9
  try {
15
10
  const queryBuilder = repository
@@ -23,7 +18,7 @@ export async function getLocalsCompanyInformationTable(
23
18
  "global"
24
19
  ].value.toLowerCase()}%`;
25
20
  queryBuilder.andWhere(
26
- "(LOWER(locals_company_information_for_the_table.name) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.address) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_name) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_surname) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_full_name) LIKE :globalValue OR locals_company_information_for_the_table.partner_full_name LIKE :globalValue",
21
+ "(LOWER(locals_company_information_for_the_table.code) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.name) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.address) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_name) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_surname) LIKE :globalValue OR LOWER(locals_company_information_for_the_table.partner_full_name) LIKE :globalValue OR locals_company_information_for_the_table.partner_full_name LIKE :globalValue)",
27
22
  { globalValue },
28
23
  );
29
24
  }
@@ -58,21 +53,6 @@ export async function getLocalsCompanyInformationTable(
58
53
  );
59
54
  }
60
55
 
61
- // DOC: la columna filter_visualization se utiliza para aplicar el filtro review_status y operation_type.
62
- // DOC: Si filter_visualization es "in-review-rejected", se muestran los locales que están en revisión o rechazados, es decir, review_status = 1 o 3 y operation_type = 1 o 2.
63
- // DOC: Si filter_visualization es "no-in-review-rejected", se muestran los locales que no están en revisión ni rechazados, es decir, review_status es null y operation_type es null.
64
- if (filter_visualization === 1) {
65
- // "in-review-rejected"
66
- queryBuilder.andWhere(
67
- "(locals_company_information_for_the_table.review_status IN (1, 3) AND locals_company_information_for_the_table.operation_type IN (1, 2))",
68
- );
69
- } else if (filter_visualization === 2) {
70
- // "no-in-review-rejected"
71
- queryBuilder.andWhere(
72
- "(locals_company_information_for_the_table.review_status IS NULL AND locals_company_information_for_the_table.operation_type IS NULL)",
73
- );
74
- }
75
-
76
56
  // DOC: Acá vienen los otros filtros, por las columnas de la tabla.
77
57
  const filters = lazyEvent.filters;
78
58
  Object.keys(filters).forEach((key) => {
@@ -97,6 +77,66 @@ export async function getLocalsCompanyInformationTable(
97
77
  switch (
98
78
  matchMode // DOC: Verificamos el modo de coincidencia del filtro.
99
79
  ) {
80
+ case "custom":
81
+ // 📌 Filtro por created / updated (rango de fechas en UTC)
82
+ if (key === "created" || key === "updated") {
83
+ if (Array.isArray(value) && value.length === 2) {
84
+ const [from, to] = value;
85
+
86
+ if (from !== null && to === null) {
87
+ queryBuilder.andWhere(`${accessKey} >= :from`, {
88
+ from: new Date(from),
89
+ });
90
+ } else if (from === null && to !== null) {
91
+ queryBuilder.andWhere(`${accessKey} <= :to`, {
92
+ to: new Date(to),
93
+ });
94
+ } else if (from !== null && to !== null) {
95
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
96
+ from: new Date(from),
97
+ to: new Date(to),
98
+ });
99
+ }
100
+ }
101
+ }
102
+
103
+ // 📌 Filtro por created_by (array de ids)
104
+ if (key === "created_by") {
105
+ if (Array.isArray(value) && value.length > 0) {
106
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
107
+ [key]: value,
108
+ });
109
+ }
110
+ }
111
+
112
+ // 📌 Filtro por updated_by (array de ids)
113
+ if (key === "updated_by") {
114
+ if (Array.isArray(value) && value.length > 0) {
115
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
116
+ [key]: value,
117
+ });
118
+ }
119
+ }
120
+
121
+ // 📌 Filtro por total_requests / average_rating (rango numérico)
122
+ if (key === "total_requests" || key === "average_rating") {
123
+ if (Array.isArray(value) && value.length === 2) {
124
+ const [from, to] = value;
125
+
126
+ if (from !== null && to === null) {
127
+ queryBuilder.andWhere(`${accessKey} >= :from`, { from });
128
+ } else if (from === null && to !== null) {
129
+ queryBuilder.andWhere(`${accessKey} <= :to`, { to });
130
+ } else if (from !== null && to !== null) {
131
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
132
+ from,
133
+ to,
134
+ });
135
+ }
136
+ }
137
+ }
138
+
139
+ break;
100
140
  case "contains": // DOC: Si el modo de coincidencia es "contains".
101
141
  queryBuilder.andWhere(`LOWER(${accessKey}) LIKE :${key}`, {
102
142
  [key]: `%${value}%`,
@@ -211,14 +251,22 @@ export async function getLocalsCompanyInformationTable(
211
251
  // DOC: Ejecutamos la consulta y obtenemos los resultados.
212
252
  const [data, totalRecords] = await queryBuilder.getManyAndCount();
213
253
 
254
+ // DOC: Si quieres ver la consulta generada, puedes descomentar las siguientes líneas:
255
+ // console.log("Query:", queryBuilder.getQuery());
256
+ console.log("Query:", queryBuilder.getQueryAndParameters());
257
+
214
258
  return {
215
259
  data,
216
260
  totalRecords,
261
+ query: queryBuilder.getQueryAndParameters(),
217
262
  };
218
263
  } catch (error) {
264
+ console.log(error, "error por acá");
265
+
219
266
  return {
220
267
  data: [],
221
268
  totalRecords: 0,
269
+ query: null,
222
270
  };
223
271
  }
224
272
  }
package/src/index.ts CHANGED
@@ -3,6 +3,15 @@ import { config } from "dotenv";
3
3
  import { NextFunction, Request, Response } from "express";
4
4
  import { resolve } from "path";
5
5
  import { DataSource, EntityTarget, ObjectLiteral, Repository } from "typeorm";
6
+ import * as EntitiesViewsRoutes from "./entities.index";
7
+ import {
8
+ getDiscountsCodeCompanyInformation,
9
+ getDiscountsCodeUserInformation,
10
+ getLocalReservesInformation,
11
+ getLocalsCompanyInformation,
12
+ getLocalsCompanyInformationTable,
13
+ getVerifyLocalsInformation
14
+ } from "./entities.views.routes";
6
15
  import {
7
16
  IBasicCompany,
8
17
  IBasicLazyEvent,
@@ -12,17 +21,7 @@ import {
12
21
  IType,
13
22
  } from "./interfaces";
14
23
  import moment = require("moment-timezone");
15
- import {
16
- CustomRepository,
17
- getDiscountsCodeCompanyInformation,
18
- getDiscountsCodeUserInformation,
19
- getLocalReservesInformation,
20
- getLocalsCompanyInformation,
21
- getLocalsCompanyInformationTable,
22
- getVerifyLocalsInformation,
23
- } from "./entities.views.routes";
24
24
  export * from "./entities.views.routes";
25
- import * as EntitiesViewsRoutes from "./entities.index";
26
25
 
27
26
  const asyncLocalStorage = new AsyncLocalStorage<Map<string, string>>();
28
27
 
package/src/interfaces.ts CHANGED
@@ -32,7 +32,6 @@ export interface IBasicCompany extends IBasicLazyEvent {
32
32
  company: number | null;
33
33
  visible?: number | null;
34
34
  owner?: number | null;
35
- filter_visualization?: number | null;
36
35
  }
37
36
 
38
37
  export interface IPropsQueryVerifyLocalInformation extends IPropsQueryVerifyLocal {