test-entity-library-asm 3.9.57 → 3.9.58

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,6 +1,6 @@
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
6
  }>;
@@ -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.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,6 +209,9 @@ 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,
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.58",
4
4
  "description": "Entidades de ejemplo para una base de datos",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -3,13 +3,7 @@ import { IBasicCompany } from "../interfaces";
3
3
 
4
4
  export async function getLocalsCompanyInformationTable(
5
5
  repository: Repository<any>,
6
- {
7
- company,
8
- status,
9
- visible,
10
- lazyEvent,
11
- filter_visualization = 2, // "no-in-review-rejected"
12
- }: IBasicCompany,
6
+ { company, status, visible, lazyEvent }: IBasicCompany,
13
7
  ) {
14
8
  try {
15
9
  const queryBuilder = repository
@@ -23,7 +17,7 @@ export async function getLocalsCompanyInformationTable(
23
17
  "global"
24
18
  ].value.toLowerCase()}%`;
25
19
  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",
20
+ "(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
21
  { globalValue },
28
22
  );
29
23
  }
@@ -58,21 +52,6 @@ export async function getLocalsCompanyInformationTable(
58
52
  );
59
53
  }
60
54
 
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
55
  // DOC: Acá vienen los otros filtros, por las columnas de la tabla.
77
56
  const filters = lazyEvent.filters;
78
57
  Object.keys(filters).forEach((key) => {
@@ -97,6 +76,66 @@ export async function getLocalsCompanyInformationTable(
97
76
  switch (
98
77
  matchMode // DOC: Verificamos el modo de coincidencia del filtro.
99
78
  ) {
79
+ case "custom":
80
+ // 📌 Filtro por created / updated (rango de fechas en UTC)
81
+ if (key === "created" || key === "updated") {
82
+ if (Array.isArray(value) && value.length === 2) {
83
+ const [from, to] = value;
84
+
85
+ if (from !== null && to === null) {
86
+ queryBuilder.andWhere(`${accessKey} >= :from`, {
87
+ from: new Date(from),
88
+ });
89
+ } else if (from === null && to !== null) {
90
+ queryBuilder.andWhere(`${accessKey} <= :to`, {
91
+ to: new Date(to),
92
+ });
93
+ } else if (from !== null && to !== null) {
94
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
95
+ from: new Date(from),
96
+ to: new Date(to),
97
+ });
98
+ }
99
+ }
100
+ }
101
+
102
+ // 📌 Filtro por created_by (array de ids)
103
+ if (key === "created_by") {
104
+ if (Array.isArray(value) && value.length > 0) {
105
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
106
+ [key]: value,
107
+ });
108
+ }
109
+ }
110
+
111
+ // 📌 Filtro por updated_by (array de ids)
112
+ if (key === "updated_by") {
113
+ if (Array.isArray(value) && value.length > 0) {
114
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
115
+ [key]: value,
116
+ });
117
+ }
118
+ }
119
+
120
+ // 📌 Filtro por total_requests / average_rating (rango numérico)
121
+ if (key === "total_requests" || key === "average_rating") {
122
+ if (Array.isArray(value) && value.length === 2) {
123
+ const [from, to] = value;
124
+
125
+ if (from !== null && to === null) {
126
+ queryBuilder.andWhere(`${accessKey} >= :from`, { from });
127
+ } else if (from === null && to !== null) {
128
+ queryBuilder.andWhere(`${accessKey} <= :to`, { to });
129
+ } else if (from !== null && to !== null) {
130
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
131
+ from,
132
+ to,
133
+ });
134
+ }
135
+ }
136
+ }
137
+
138
+ break;
100
139
  case "contains": // DOC: Si el modo de coincidencia es "contains".
101
140
  queryBuilder.andWhere(`LOWER(${accessKey}) LIKE :${key}`, {
102
141
  [key]: `%${value}%`,
@@ -211,6 +250,10 @@ export async function getLocalsCompanyInformationTable(
211
250
  // DOC: Ejecutamos la consulta y obtenemos los resultados.
212
251
  const [data, totalRecords] = await queryBuilder.getManyAndCount();
213
252
 
253
+ // DOC: Si quieres ver la consulta generada, puedes descomentar las siguientes líneas:
254
+ // console.log("Query:", queryBuilder.getQuery());
255
+ // console.log("Query:", queryBuilder.getQueryAndParameters());
256
+
214
257
  return {
215
258
  data,
216
259
  totalRecords,
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 {