test-entity-library-asm 3.9.65 → 3.9.66

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.
@@ -4,7 +4,6 @@ exports.getDiscountsCodeUserInformation = void 0;
4
4
  const __1 = require("..");
5
5
  async function getDiscountsCodeUserInformation(repository, { status, company, lazyEvent }) {
6
6
  try {
7
- const timezone = (0, __1.getTimezoneOffset)((0, __1.getTimeZone)());
8
7
  const queryBuilder = repository
9
8
  .createQueryBuilder("discount_code_user")
10
9
  .skip(lazyEvent.first)
@@ -12,7 +11,7 @@ async function getDiscountsCodeUserInformation(repository, { status, company, la
12
11
  // DOC: Filtro global
13
12
  if (lazyEvent.filters["global"] && lazyEvent.filters["global"].value) {
14
13
  const globalValue = `%${lazyEvent.filters["global"].value.toLowerCase()}%`;
15
- queryBuilder.andWhere("(LOWER(discount_code_user.local_name) LIKE :globalValue OR LOWER(partner_surname) LIKE :globalValue OR LOWER(discount_code_user.code) LIKE :globalValue OR LOWER(discount_code_user.discount) LIKE :globalValue OR LOWER(partner_name) LIKE :globalValue)", {
14
+ queryBuilder.andWhere("(LOWER(discount_code_user.local_name) LIKE :globalValue OR LOWER(discount_code_user.created_by_name) LIKE :globalValue OR LOWER(discount_code_user.created_by_surname) LIKE :globalValue OR LOWER(discount_code_user.code) LIKE :globalValue OR LOWER(discount_code_user.discount) LIKE :globalValue OR LOWER(partner_name) LIKE :globalValue OR LOWER(discount_code_user.partner_surname) LIKE :globalValue OR discount_code_user.number_of_times_used LIKE :globalValue OR discount_code_user.use_limit LIKE :globalValue OR discount_code_user.start LIKE :globalValue OR discount_code_user.expiration LIKE :globalValue)", {
16
15
  globalValue: globalValue ||
17
16
  (0, __1.getStatusBasic)(lazyEvent.filters["global"].value.toLowerCase()) ||
18
17
  (0, __1.getSeverityNameDiscountType)(lazyEvent.filters["global"].value.toLowerCase()),
@@ -43,23 +42,83 @@ async function getDiscountsCodeUserInformation(repository, { status, company, la
43
42
  const accessKey = key.split(".").length > 1 ? `${key}` : `discount_code_user.${key}`;
44
43
  switch (matchMode) {
45
44
  case "custom":
46
- if ((key === "number_of_times_used" || key === "use_limit") &&
45
+ // 📌 Filtro por created / updated (rango de fechas en UTC)
46
+ if (key === "created" || key === "updated") {
47
+ if (Array.isArray(value) && value.length === 2) {
48
+ const [from, to] = value;
49
+ if (from !== null && to === null) {
50
+ queryBuilder.andWhere(`${accessKey} >= :from`, {
51
+ from: new Date(from),
52
+ });
53
+ }
54
+ else if (from === null && to !== null) {
55
+ queryBuilder.andWhere(`${accessKey} <= :to`, {
56
+ to: new Date(to),
57
+ });
58
+ }
59
+ else if (from !== null && to !== null) {
60
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
61
+ from: new Date(from),
62
+ to: new Date(to),
63
+ });
64
+ }
65
+ }
66
+ }
67
+ if ((key === "number_of_times_used" ||
68
+ key === "use_limit" ||
69
+ key === "discount") &&
47
70
  matchMode === "custom") {
48
71
  const [from, to] = value || [null, null];
49
72
  if (from !== null && to === null) {
50
- queryBuilder.andWhere(`discount_code_user.${key} >= :from`, {
73
+ queryBuilder.andWhere(`${accessKey} >= :from`, {
51
74
  from,
52
75
  });
53
76
  }
54
77
  else if (from === null && to !== null) {
55
- queryBuilder.andWhere(`discount_code_user.${key} <= :to`, {
78
+ queryBuilder.andWhere(`${accessKey} <= :to`, {
56
79
  to,
57
80
  });
58
81
  }
59
82
  else if (from !== null && to !== null) {
60
- queryBuilder.andWhere(`discount_code_user.${key} BETWEEN :from AND :to`, { from, to });
83
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
84
+ from,
85
+ to,
86
+ });
87
+ }
88
+ }
89
+ // 📌 Filtro por created_by (array de ids)
90
+ if (key === "created_by") {
91
+ if (Array.isArray(value) && value.length > 0) {
92
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
93
+ [key]: value,
94
+ });
95
+ }
96
+ }
97
+ // 📌 Filtro por updated_by (array de ids)
98
+ if (key === "updated_by") {
99
+ if (Array.isArray(value) && value.length > 0) {
100
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
101
+ [key]: value,
102
+ });
61
103
  }
62
104
  }
105
+ if (key === "local") {
106
+ if (Array.isArray(value) && value.length > 0) {
107
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
108
+ [key]: value,
109
+ });
110
+ }
111
+ }
112
+ // if (key === "repeat_days") {
113
+ // if (Array.isArray(value) && value.length > 0) {
114
+ // const conditions = value.map((day, index) => {
115
+ // const param = `${key}_${index}`;
116
+ // queryBuilder.setParameter(param, `"${day}"`);
117
+ // return `JSON_CONTAINS(discount_code_user.repeat_days, :${param})`;
118
+ // });
119
+ // queryBuilder.andWhere(`(${conditions.join(" OR ")})`);
120
+ // }
121
+ // }
63
122
  break;
64
123
  case "contains":
65
124
  queryBuilder.andWhere(`${accessKey} LIKE :${key}`, {
@@ -77,29 +136,31 @@ async function getDiscountsCodeUserInformation(repository, { status, company, la
77
136
  });
78
137
  break;
79
138
  case "equals":
80
- if (key === "status") {
81
- queryBuilder.andWhere("discount_code_user.status = :status", {
82
- status: (0, __1.getStatusBasic)(filters[key].value ?? ""),
83
- });
84
- }
85
- else if (key === "typeText") {
86
- queryBuilder.andWhere("discount_code_user.type = :type", {
87
- type: (0, __1.getSeverityNameDiscountType)(filters[key].value ?? ""),
88
- });
89
- }
90
- else if (key === "updated_by") {
91
- const updatedByIds = filters[key].value.map((element) => element.id);
92
- if (updatedByIds.length > 0) {
93
- queryBuilder.andWhere("discount_code_user.updated_by IN (:...updatedByIds)", {
94
- updatedByIds,
95
- });
96
- }
97
- }
98
- else {
99
- queryBuilder.andWhere(`${accessKey} = :${key}`, {
100
- [key]: value,
101
- });
102
- }
139
+ // if (key === "status") {
140
+ // queryBuilder.andWhere("discount_code_user.status = :status", {
141
+ // status: getStatusBasic(filters[key].value ?? ""),
142
+ // });
143
+ // } else if (key === "typeText") {
144
+ // queryBuilder.andWhere("discount_code_user.type = :type", {
145
+ // type: getSeverityNameDiscountType(filters[key].value ?? ""),
146
+ // });
147
+ // } else if (key === "updated_by") {
148
+ // const updatedByIds = filters[key].value.map(
149
+ // (element: Partner) => element.id,
150
+ // );
151
+ // if (updatedByIds.length > 0) {
152
+ // queryBuilder.andWhere(
153
+ // "discount_code_user.updated_by IN (:...updatedByIds)",
154
+ // {
155
+ // updatedByIds,
156
+ // },
157
+ // );
158
+ // }
159
+ // } else {
160
+ // }
161
+ queryBuilder.andWhere(`${accessKey} = :${key}`, {
162
+ [key]: value,
163
+ });
103
164
  break;
104
165
  case "notContains":
105
166
  queryBuilder.andWhere(`${accessKey} NOT LIKE :${key}`, {
@@ -111,40 +172,75 @@ async function getDiscountsCodeUserInformation(repository, { status, company, la
111
172
  [key]: value,
112
173
  });
113
174
  break;
114
- case "dateIs":
115
- queryBuilder.andWhere(`${key !== "expiration" && key !== "start"
116
- ? "DATE(CONVERT_TZ("
117
- : ""} ${accessKey} ${key !== "expiration" && key !== "start"
118
- ? `, '+00:00', '${timezone}'))`
119
- : ""} = :${key}`, {
120
- [key]: value.split("T")[0],
175
+ case "in": // DOC: Si el modo de coincidencia es "in".
176
+ if (Array.isArray(value)) {
177
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
178
+ [key]: value,
179
+ });
180
+ }
181
+ break;
182
+ case "notIn": // DOC: Si el modo de coincidencia es "notIn
183
+ if (Array.isArray(value)) {
184
+ queryBuilder.andWhere(`${accessKey} NOT IN (:...${key})`, {
185
+ [key]: value,
186
+ });
187
+ }
188
+ break;
189
+ case "lt": // DOC: Si el modo de coincidencia es "lt" (less than).
190
+ queryBuilder.andWhere(`${accessKey} < :${key}`, { [key]: value });
191
+ break;
192
+ case "lte": // DOC: Si el modo de coincidencia es "lte" (less than or equal).
193
+ queryBuilder.andWhere(`${accessKey} <= :${key}`, { [key]: value });
194
+ break;
195
+ case "gt": // DOC: Si el modo de coincidencia es "gt" (greater than).
196
+ queryBuilder.andWhere(`${accessKey} > :${key}`, { [key]: value });
197
+ break;
198
+ case "gte": // DOC: Si el modo de coincidencia es "gte" (greater than or equal).
199
+ queryBuilder.andWhere(`${accessKey} >= :${key}`, { [key]: value });
200
+ break;
201
+ case "between": // DOC: Si el modo de coincidencia es "between".
202
+ if (Array.isArray(value) && value.length === 2) {
203
+ const [from, to] = value;
204
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
205
+ from,
206
+ to,
207
+ });
208
+ }
209
+ break;
210
+ case "dateIs": {
211
+ // DOC: Si el modo de coincidencia es "dateIs". Hay que tener en cuenta la zona horaria (timezone)
212
+ const date = new Date(value);
213
+ const start = new Date(date);
214
+ start.setUTCHours(0, 0, 0, 0);
215
+ const end = new Date(date);
216
+ end.setUTCHours(23, 59, 59, 999);
217
+ queryBuilder.andWhere(`${accessKey} BETWEEN :start AND :end`, {
218
+ start,
219
+ end,
121
220
  });
122
221
  break;
123
- case "dateIsNot":
124
- queryBuilder.andWhere(`${key !== "expiration" && key !== "start"
125
- ? "DATE(CONVERT_TZ("
126
- : ""} ${accessKey} ${key !== "expiration" && key !== "start"
127
- ? `, '+00:00', '${timezone}'))`
128
- : ""} != :${key}`, {
129
- [key]: value.split("T")[0],
222
+ }
223
+ case "dateIsNot": {
224
+ // DOC: Si el modo de coincidencia es "dateIsNot". Hay que tener en cuenta la zona horaria (timezone)
225
+ const date = new Date(value);
226
+ const start = new Date(date);
227
+ start.setUTCHours(0, 0, 0, 0);
228
+ const end = new Date(date);
229
+ end.setUTCHours(23, 59, 59, 999);
230
+ queryBuilder.andWhere(`${accessKey} NOT BETWEEN :start AND :end`, {
231
+ start,
232
+ end,
130
233
  });
131
234
  break;
132
- case "dateBefore":
133
- queryBuilder.andWhere(`${key !== "expiration" && key !== "start"
134
- ? "DATE(CONVERT_TZ("
135
- : ""} ${accessKey} ${key !== "expiration" && key !== "start"
136
- ? `, '+00:00', '${timezone}'))`
137
- : ""} < :${key}`, {
138
- [key]: value.split("T")[0],
235
+ }
236
+ case "dateBefore": // DOC: Si el modo de coincidencia es "dateBefore". Hay que tener en cuenta la zona horaria (timezone)
237
+ queryBuilder.andWhere(`${accessKey} < :${key}`, {
238
+ [key]: new Date(value),
139
239
  });
140
240
  break;
141
- case "dateAfter":
142
- queryBuilder.andWhere(`${key !== "expiration" && key !== "start"
143
- ? "DATE(CONVERT_TZ("
144
- : ""} ${accessKey} ${key !== "expiration" && key !== "start"
145
- ? `, '+00:00', '${timezone}'))`
146
- : ""} > :${key}`, {
147
- [key]: value.split("T")[0],
241
+ case "dateAfter": // DOC: Si el modo de coincidencia es "dateAfter". Hay que tener en cuenta la zona horaria (timezone)
242
+ queryBuilder.andWhere(`${accessKey} > :${key}`, {
243
+ [key]: new Date(value),
148
244
  });
149
245
  break;
150
246
  default:
@@ -155,25 +251,22 @@ async function getDiscountsCodeUserInformation(repository, { status, company, la
155
251
  // DOC: Ordenamiento
156
252
  if (lazyEvent.sortField) {
157
253
  const order = lazyEvent.sortOrder === 1 ? "ASC" : "DESC";
158
- if (lazyEvent.sortField === "local.name") {
159
- queryBuilder.orderBy(`local.name`, order);
160
- }
161
- else {
162
- if (lazyEvent.sortField === "typeText") {
163
- queryBuilder.orderBy(`discount_code_user.type`, order);
164
- }
165
- else if (lazyEvent.sortField === "status") {
166
- queryBuilder.orderBy(`discount_code_user.status`, order);
167
- }
168
- else {
169
- queryBuilder.orderBy(`discount_code_user.${lazyEvent.sortField}`, order);
170
- }
171
- }
254
+ // if (lazyEvent.sortField === "local.name") {
255
+ // queryBuilder.orderBy(`local.name`, order);
256
+ // } else {
257
+ // if (lazyEvent.sortField === "typeText") {
258
+ // queryBuilder.orderBy(`discount_code_user.type`, order);
259
+ // } else if (lazyEvent.sortField === "status") {
260
+ // queryBuilder.orderBy(`discount_code_user.status`, order);
261
+ // } else {
262
+ // }
263
+ // }
264
+ queryBuilder.orderBy(`discount_code_user.${lazyEvent.sortField}`, order);
172
265
  }
173
266
  // DOC: Ejecutar la consulta
174
- const [discountsCodeUser, totalRecords] = await queryBuilder.getManyAndCount();
267
+ const [data, totalRecords] = await queryBuilder.getManyAndCount();
175
268
  return {
176
- data: discountsCodeUser,
269
+ data,
177
270
  totalRecords,
178
271
  };
179
272
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "3.9.65",
3
+ "version": "3.9.66",
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,20 +1,12 @@
1
1
  import { Repository } from "typeorm";
2
- import {
3
- getSeverityNameDiscountType,
4
- getStatusBasic,
5
- getTimeZone,
6
- getTimezoneOffset,
7
- Partner,
8
- } from "..";
2
+ import { getSeverityNameDiscountType, getStatusBasic } from "..";
9
3
  import { IPropsDiscountUserOrCompany } from "../interfaces";
10
4
 
11
5
  export async function getDiscountsCodeUserInformation(
12
6
  repository: Repository<any>,
13
- { status, company, lazyEvent }: IPropsDiscountUserOrCompany
7
+ { status, company, lazyEvent }: IPropsDiscountUserOrCompany,
14
8
  ) {
15
9
  try {
16
- const timezone = getTimezoneOffset(getTimeZone());
17
-
18
10
  const queryBuilder = repository
19
11
  .createQueryBuilder("discount_code_user")
20
12
  .skip(lazyEvent.first)
@@ -26,15 +18,15 @@ export async function getDiscountsCodeUserInformation(
26
18
  "global"
27
19
  ].value.toLowerCase()}%`;
28
20
  queryBuilder.andWhere(
29
- "(LOWER(discount_code_user.local_name) LIKE :globalValue OR LOWER(partner_surname) LIKE :globalValue OR LOWER(discount_code_user.code) LIKE :globalValue OR LOWER(discount_code_user.discount) LIKE :globalValue OR LOWER(partner_name) LIKE :globalValue)",
21
+ "(LOWER(discount_code_user.local_name) LIKE :globalValue OR LOWER(discount_code_user.created_by_name) LIKE :globalValue OR LOWER(discount_code_user.created_by_surname) LIKE :globalValue OR LOWER(discount_code_user.code) LIKE :globalValue OR LOWER(discount_code_user.discount) LIKE :globalValue OR LOWER(partner_name) LIKE :globalValue OR LOWER(discount_code_user.partner_surname) LIKE :globalValue OR discount_code_user.number_of_times_used LIKE :globalValue OR discount_code_user.use_limit LIKE :globalValue OR discount_code_user.start LIKE :globalValue OR discount_code_user.expiration LIKE :globalValue)",
30
22
  {
31
23
  globalValue:
32
24
  globalValue ||
33
25
  getStatusBasic(lazyEvent.filters["global"].value.toLowerCase()) ||
34
26
  getSeverityNameDiscountType(
35
- lazyEvent.filters["global"].value.toLowerCase()
27
+ lazyEvent.filters["global"].value.toLowerCase(),
36
28
  ),
37
- }
29
+ },
38
30
  );
39
31
  }
40
32
 
@@ -69,27 +61,89 @@ export async function getDiscountsCodeUserInformation(
69
61
 
70
62
  switch (matchMode) {
71
63
  case "custom":
64
+ // 📌 Filtro por created / updated (rango de fechas en UTC)
65
+ if (key === "created" || key === "updated") {
66
+ if (Array.isArray(value) && value.length === 2) {
67
+ const [from, to] = value;
68
+
69
+ if (from !== null && to === null) {
70
+ queryBuilder.andWhere(`${accessKey} >= :from`, {
71
+ from: new Date(from),
72
+ });
73
+ } else if (from === null && to !== null) {
74
+ queryBuilder.andWhere(`${accessKey} <= :to`, {
75
+ to: new Date(to),
76
+ });
77
+ } else if (from !== null && to !== null) {
78
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
79
+ from: new Date(from),
80
+ to: new Date(to),
81
+ });
82
+ }
83
+ }
84
+ }
85
+
72
86
  if (
73
- (key === "number_of_times_used" || key === "use_limit") &&
87
+ (key === "number_of_times_used" ||
88
+ key === "use_limit" ||
89
+ key === "discount") &&
74
90
  matchMode === "custom"
75
91
  ) {
76
92
  const [from, to] = value || [null, null];
77
93
 
78
94
  if (from !== null && to === null) {
79
- queryBuilder.andWhere(`discount_code_user.${key} >= :from`, {
95
+ queryBuilder.andWhere(`${accessKey} >= :from`, {
80
96
  from,
81
97
  });
82
98
  } else if (from === null && to !== null) {
83
- queryBuilder.andWhere(`discount_code_user.${key} <= :to`, {
99
+ queryBuilder.andWhere(`${accessKey} <= :to`, {
84
100
  to,
85
101
  });
86
102
  } else if (from !== null && to !== null) {
87
- queryBuilder.andWhere(
88
- `discount_code_user.${key} BETWEEN :from AND :to`,
89
- { from, to }
90
- );
103
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
104
+ from,
105
+ to,
106
+ });
107
+ }
108
+ }
109
+
110
+ // 📌 Filtro por created_by (array de ids)
111
+ if (key === "created_by") {
112
+ if (Array.isArray(value) && value.length > 0) {
113
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
114
+ [key]: value,
115
+ });
116
+ }
117
+ }
118
+
119
+ // 📌 Filtro por updated_by (array de ids)
120
+ if (key === "updated_by") {
121
+ if (Array.isArray(value) && value.length > 0) {
122
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
123
+ [key]: value,
124
+ });
125
+ }
126
+ }
127
+
128
+ if (key === "local") {
129
+ if (Array.isArray(value) && value.length > 0) {
130
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
131
+ [key]: value,
132
+ });
91
133
  }
92
134
  }
135
+
136
+ // if (key === "repeat_days") {
137
+ // if (Array.isArray(value) && value.length > 0) {
138
+ // const conditions = value.map((day, index) => {
139
+ // const param = `${key}_${index}`;
140
+ // queryBuilder.setParameter(param, `"${day}"`);
141
+ // return `JSON_CONTAINS(discount_code_user.repeat_days, :${param})`;
142
+ // });
143
+
144
+ // queryBuilder.andWhere(`(${conditions.join(" OR ")})`);
145
+ // }
146
+ // }
93
147
  break;
94
148
  case "contains":
95
149
  queryBuilder.andWhere(`${accessKey} LIKE :${key}`, {
@@ -107,32 +161,32 @@ export async function getDiscountsCodeUserInformation(
107
161
  });
108
162
  break;
109
163
  case "equals":
110
- if (key === "status") {
111
- queryBuilder.andWhere("discount_code_user.status = :status", {
112
- status: getStatusBasic(filters[key].value ?? ""),
113
- });
114
- } else if (key === "typeText") {
115
- queryBuilder.andWhere("discount_code_user.type = :type", {
116
- type: getSeverityNameDiscountType(filters[key].value ?? ""),
117
- });
118
- } else if (key === "updated_by") {
119
- const updatedByIds = filters[key].value.map(
120
- (element: Partner) => element.id
121
- );
122
-
123
- if (updatedByIds.length > 0) {
124
- queryBuilder.andWhere(
125
- "discount_code_user.updated_by IN (:...updatedByIds)",
126
- {
127
- updatedByIds,
128
- }
129
- );
130
- }
131
- } else {
132
- queryBuilder.andWhere(`${accessKey} = :${key}`, {
133
- [key]: value,
134
- });
135
- }
164
+ // if (key === "status") {
165
+ // queryBuilder.andWhere("discount_code_user.status = :status", {
166
+ // status: getStatusBasic(filters[key].value ?? ""),
167
+ // });
168
+ // } else if (key === "typeText") {
169
+ // queryBuilder.andWhere("discount_code_user.type = :type", {
170
+ // type: getSeverityNameDiscountType(filters[key].value ?? ""),
171
+ // });
172
+ // } else if (key === "updated_by") {
173
+ // const updatedByIds = filters[key].value.map(
174
+ // (element: Partner) => element.id,
175
+ // );
176
+
177
+ // if (updatedByIds.length > 0) {
178
+ // queryBuilder.andWhere(
179
+ // "discount_code_user.updated_by IN (:...updatedByIds)",
180
+ // {
181
+ // updatedByIds,
182
+ // },
183
+ // );
184
+ // }
185
+ // } else {
186
+ // }
187
+ queryBuilder.andWhere(`${accessKey} = :${key}`, {
188
+ [key]: value,
189
+ });
136
190
  break;
137
191
  case "notContains":
138
192
  queryBuilder.andWhere(`${accessKey} NOT LIKE :${key}`, {
@@ -144,69 +198,80 @@ export async function getDiscountsCodeUserInformation(
144
198
  [key]: value,
145
199
  });
146
200
  break;
147
- case "dateIs":
148
- queryBuilder.andWhere(
149
- `${
150
- key !== "expiration" && key !== "start"
151
- ? "DATE(CONVERT_TZ("
152
- : ""
153
- } ${accessKey} ${
154
- key !== "expiration" && key !== "start"
155
- ? `, '+00:00', '${timezone}'))`
156
- : ""
157
- } = :${key}`,
158
- {
159
- [key]: value.split("T")[0],
160
- }
161
- );
162
- break;
163
- case "dateIsNot":
164
- queryBuilder.andWhere(
165
- `${
166
- key !== "expiration" && key !== "start"
167
- ? "DATE(CONVERT_TZ("
168
- : ""
169
- } ${accessKey} ${
170
- key !== "expiration" && key !== "start"
171
- ? `, '+00:00', '${timezone}'))`
172
- : ""
173
- } != :${key}`,
174
- {
175
- [key]: value.split("T")[0],
176
- }
177
- );
178
- break;
179
- case "dateBefore":
180
- queryBuilder.andWhere(
181
- `${
182
- key !== "expiration" && key !== "start"
183
- ? "DATE(CONVERT_TZ("
184
- : ""
185
- } ${accessKey} ${
186
- key !== "expiration" && key !== "start"
187
- ? `, '+00:00', '${timezone}'))`
188
- : ""
189
- } < :${key}`,
190
- {
191
- [key]: value.split("T")[0],
192
- }
193
- );
194
- break;
195
- case "dateAfter":
196
- queryBuilder.andWhere(
197
- `${
198
- key !== "expiration" && key !== "start"
199
- ? "DATE(CONVERT_TZ("
200
- : ""
201
- } ${accessKey} ${
202
- key !== "expiration" && key !== "start"
203
- ? `, '+00:00', '${timezone}'))`
204
- : ""
205
- } > :${key}`,
206
- {
207
- [key]: value.split("T")[0],
208
- }
209
- );
201
+ case "in": // DOC: Si el modo de coincidencia es "in".
202
+ if (Array.isArray(value)) {
203
+ queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
204
+ [key]: value,
205
+ });
206
+ }
207
+ break;
208
+ case "notIn": // DOC: Si el modo de coincidencia es "notIn
209
+ if (Array.isArray(value)) {
210
+ queryBuilder.andWhere(`${accessKey} NOT IN (:...${key})`, {
211
+ [key]: value,
212
+ });
213
+ }
214
+ break;
215
+ case "lt": // DOC: Si el modo de coincidencia es "lt" (less than).
216
+ queryBuilder.andWhere(`${accessKey} < :${key}`, { [key]: value });
217
+ break;
218
+ case "lte": // DOC: Si el modo de coincidencia es "lte" (less than or equal).
219
+ queryBuilder.andWhere(`${accessKey} <= :${key}`, { [key]: value });
220
+ break;
221
+ case "gt": // DOC: Si el modo de coincidencia es "gt" (greater than).
222
+ queryBuilder.andWhere(`${accessKey} > :${key}`, { [key]: value });
223
+ break;
224
+ case "gte": // DOC: Si el modo de coincidencia es "gte" (greater than or equal).
225
+ queryBuilder.andWhere(`${accessKey} >= :${key}`, { [key]: value });
226
+ break;
227
+ case "between": // DOC: Si el modo de coincidencia es "between".
228
+ if (Array.isArray(value) && value.length === 2) {
229
+ const [from, to] = value;
230
+ queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
231
+ from,
232
+ to,
233
+ });
234
+ }
235
+ break;
236
+ case "dateIs": {
237
+ // DOC: Si el modo de coincidencia es "dateIs". Hay que tener en cuenta la zona horaria (timezone)
238
+ const date = new Date(value);
239
+ const start = new Date(date);
240
+ start.setUTCHours(0, 0, 0, 0);
241
+
242
+ const end = new Date(date);
243
+ end.setUTCHours(23, 59, 59, 999);
244
+
245
+ queryBuilder.andWhere(`${accessKey} BETWEEN :start AND :end`, {
246
+ start,
247
+ end,
248
+ });
249
+ break;
250
+ }
251
+ case "dateIsNot": {
252
+ // DOC: Si el modo de coincidencia es "dateIsNot". Hay que tener en cuenta la zona horaria (timezone)
253
+ const date = new Date(value);
254
+ const start = new Date(date);
255
+ start.setUTCHours(0, 0, 0, 0);
256
+
257
+ const end = new Date(date);
258
+ end.setUTCHours(23, 59, 59, 999);
259
+
260
+ queryBuilder.andWhere(`${accessKey} NOT BETWEEN :start AND :end`, {
261
+ start,
262
+ end,
263
+ });
264
+ break;
265
+ }
266
+ case "dateBefore": // DOC: Si el modo de coincidencia es "dateBefore". Hay que tener en cuenta la zona horaria (timezone)
267
+ queryBuilder.andWhere(`${accessKey} < :${key}`, {
268
+ [key]: new Date(value),
269
+ });
270
+ break;
271
+ case "dateAfter": // DOC: Si el modo de coincidencia es "dateAfter". Hay que tener en cuenta la zona horaria (timezone)
272
+ queryBuilder.andWhere(`${accessKey} > :${key}`, {
273
+ [key]: new Date(value),
274
+ });
210
275
  break;
211
276
  default:
212
277
  break;
@@ -218,28 +283,24 @@ export async function getDiscountsCodeUserInformation(
218
283
  if (lazyEvent.sortField) {
219
284
  const order = lazyEvent.sortOrder === 1 ? "ASC" : "DESC";
220
285
 
221
- if (lazyEvent.sortField === "local.name") {
222
- queryBuilder.orderBy(`local.name`, order);
223
- } else {
224
- if (lazyEvent.sortField === "typeText") {
225
- queryBuilder.orderBy(`discount_code_user.type`, order);
226
- } else if (lazyEvent.sortField === "status") {
227
- queryBuilder.orderBy(`discount_code_user.status`, order);
228
- } else {
229
- queryBuilder.orderBy(
230
- `discount_code_user.${lazyEvent.sortField}`,
231
- order
232
- );
233
- }
234
- }
286
+ // if (lazyEvent.sortField === "local.name") {
287
+ // queryBuilder.orderBy(`local.name`, order);
288
+ // } else {
289
+ // if (lazyEvent.sortField === "typeText") {
290
+ // queryBuilder.orderBy(`discount_code_user.type`, order);
291
+ // } else if (lazyEvent.sortField === "status") {
292
+ // queryBuilder.orderBy(`discount_code_user.status`, order);
293
+ // } else {
294
+ // }
295
+ // }
296
+ queryBuilder.orderBy(`discount_code_user.${lazyEvent.sortField}`, order);
235
297
  }
236
298
 
237
299
  // DOC: Ejecutar la consulta
238
- const [discountsCodeUser, totalRecords] =
239
- await queryBuilder.getManyAndCount();
300
+ const [data, totalRecords] = await queryBuilder.getManyAndCount();
240
301
 
241
302
  return {
242
- data: discountsCodeUser,
303
+ data,
243
304
  totalRecords,
244
305
  };
245
306
  } catch (error) {