test-entity-library-asm 2.7.3 → 2.7.4

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,10 +1,14 @@
1
1
  import { DataSource, EntityTarget, Repository, ObjectLiteral } from 'typeorm';
2
- import { IPropsQueryVerifyLocal } from './interfaces';
2
+ import { IPropsDiscountUserOrCompany, IPropsQueryVerifyLocal } from './interfaces';
3
3
  export declare class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
4
4
  constructor(target: EntityTarget<T>, dataSource: DataSource);
5
5
  getVerifyLocals({ status, lazyEvent }: IPropsQueryVerifyLocal): Promise<{
6
6
  data: T[];
7
7
  totalRecords: number;
8
8
  }>;
9
+ getDiscountCodeUser({ status, company, lazyEvent, }: IPropsDiscountUserOrCompany): Promise<{
10
+ data: T[];
11
+ totalRecords: number;
12
+ }>;
9
13
  anyOtherRepository(args: any): Promise<void>;
10
14
  }
@@ -54,6 +54,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
54
54
  exports.CustomRepository = void 0;
55
55
  var typeorm_1 = require("typeorm");
56
56
  var utils_1 = require("./utils");
57
+ var _1 = require(".");
57
58
  var CustomRepository = /** @class */ (function (_super) {
58
59
  __extends(CustomRepository, _super);
59
60
  function CustomRepository(target, dataSource) {
@@ -169,6 +170,190 @@ var CustomRepository = /** @class */ (function (_super) {
169
170
  });
170
171
  });
171
172
  };
173
+ CustomRepository.prototype.getDiscountCodeUser = function (_a) {
174
+ return __awaiter(this, arguments, void 0, function (_b) {
175
+ var timezone, queryBuilder, globalValue, filters, order, _c, discountsCodeUser, totalRecords;
176
+ var status = _b.status, company = _b.company, lazyEvent = _b.lazyEvent;
177
+ return __generator(this, function (_d) {
178
+ switch (_d.label) {
179
+ case 0:
180
+ timezone = (0, _1.getTimezoneOffset)((0, _1.getTimeZone)());
181
+ queryBuilder = this.createQueryBuilder('discount_code_user')
182
+ .skip(lazyEvent.first)
183
+ .take(lazyEvent.rows);
184
+ // DOC: Filtro global
185
+ if (lazyEvent.filters['global'] && lazyEvent.filters['global'].value) {
186
+ globalValue = "%".concat(lazyEvent.filters['global'].value.toLowerCase(), "%");
187
+ queryBuilder.andWhere('LOWER(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', {
188
+ globalValue: globalValue ||
189
+ (0, utils_1.getStatusBasic)(lazyEvent.filters['global'].value.toLowerCase()) ||
190
+ (0, utils_1.getSeverityNameDiscountType)(lazyEvent.filters['global'].value.toLowerCase()),
191
+ });
192
+ }
193
+ // DOC: Filtro por estado FILTRO POR DEFECTO
194
+ if (status !== null && status >= 0) {
195
+ queryBuilder.andWhere('discount_code_user.status = :status', {
196
+ status: status,
197
+ });
198
+ }
199
+ // DOC: Filtro por company FILTRO POR DEFECTO
200
+ if (!!company && company >= 0) {
201
+ queryBuilder.andWhere('discount_code_user.company = :company', {
202
+ company: company,
203
+ });
204
+ }
205
+ filters = lazyEvent.filters;
206
+ Object.keys(filters).forEach(function (key) {
207
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
208
+ var _l, _m;
209
+ var value = filters[key].value;
210
+ if ((Array.isArray(value) && value.length > 0) ||
211
+ (!Array.isArray(value) && value && key !== 'global')) {
212
+ var matchMode = filters[key].matchMode;
213
+ if (!Array.isArray(value) && value) {
214
+ value = filters[key].value.toLowerCase();
215
+ }
216
+ var accessKey = key.split('.').length > 1 ? "".concat(key) : "discount_code_user.".concat(key);
217
+ switch (matchMode) {
218
+ case 'custom':
219
+ if ((key === 'number_of_times_used' || key === 'use_limit') &&
220
+ matchMode === 'custom') {
221
+ var _o = value || [null, null], from = _o[0], to = _o[1];
222
+ if (from !== null && to === null) {
223
+ queryBuilder.andWhere("discount_code_user.".concat(key, " >= :from"), {
224
+ from: from,
225
+ });
226
+ }
227
+ else if (from === null && to !== null) {
228
+ queryBuilder.andWhere("discount_code_user.".concat(key, " <= :to"), {
229
+ to: to,
230
+ });
231
+ }
232
+ else if (from !== null && to !== null) {
233
+ queryBuilder.andWhere("discount_code_user.".concat(key, " BETWEEN :from AND :to"), { from: from, to: to });
234
+ }
235
+ }
236
+ break;
237
+ case 'contains':
238
+ queryBuilder.andWhere("".concat(accessKey, " LIKE :").concat(key), (_a = {},
239
+ _a[key] = "%".concat(value, "%"),
240
+ _a));
241
+ break;
242
+ case 'startsWith':
243
+ queryBuilder.andWhere("".concat(accessKey, " LIKE :").concat(key), (_b = {},
244
+ _b[key] = "".concat(value, "%"),
245
+ _b));
246
+ break;
247
+ case 'endsWith':
248
+ queryBuilder.andWhere("".concat(accessKey, " LIKE :").concat(key), (_c = {},
249
+ _c[key] = "%".concat(value),
250
+ _c));
251
+ break;
252
+ case 'equals':
253
+ if (key === 'status') {
254
+ queryBuilder.andWhere('discount_code_user.status = :status', {
255
+ status: (0, utils_1.getStatusBasic)((_l = filters[key].value) !== null && _l !== void 0 ? _l : ''),
256
+ });
257
+ }
258
+ else if (key === 'typeText') {
259
+ queryBuilder.andWhere('discount_code_user.type = :type', {
260
+ type: (0, utils_1.getSeverityNameDiscountType)((_m = filters[key].value) !== null && _m !== void 0 ? _m : ''),
261
+ });
262
+ }
263
+ else if (key === 'updated_by') {
264
+ var updatedByIds = filters[key].value.map(function (element) { return element.id; });
265
+ if (updatedByIds.length > 0) {
266
+ queryBuilder.andWhere('discount_code_user.updated_by IN (:...updatedByIds)', {
267
+ updatedByIds: updatedByIds,
268
+ });
269
+ }
270
+ }
271
+ else {
272
+ queryBuilder.andWhere("".concat(accessKey, " = :").concat(key), (_d = {},
273
+ _d[key] = value,
274
+ _d));
275
+ }
276
+ break;
277
+ case 'notContains':
278
+ queryBuilder.andWhere("".concat(accessKey, " NOT LIKE :").concat(key), (_e = {},
279
+ _e[key] = "%".concat(value, "%"),
280
+ _e));
281
+ break;
282
+ case 'notEquals':
283
+ queryBuilder.andWhere("".concat(accessKey, " != :").concat(key), (_f = {},
284
+ _f[key] = value,
285
+ _f));
286
+ break;
287
+ case 'dateIs':
288
+ queryBuilder.andWhere("".concat(key !== 'expiration' && key !== 'start'
289
+ ? 'DATE(CONVERT_TZ('
290
+ : '', " ").concat(accessKey, " ").concat(key !== 'expiration' && key !== 'start'
291
+ ? ", '+00:00', '".concat(timezone, "'))")
292
+ : '', " = :").concat(key), (_g = {},
293
+ _g[key] = value.split('T')[0],
294
+ _g));
295
+ break;
296
+ case 'dateIsNot':
297
+ queryBuilder.andWhere("".concat(key !== 'expiration' && key !== 'start'
298
+ ? 'DATE(CONVERT_TZ('
299
+ : '', " ").concat(accessKey, " ").concat(key !== 'expiration' && key !== 'start'
300
+ ? ", '+00:00', '".concat(timezone, "'))")
301
+ : '', " != :").concat(key), (_h = {},
302
+ _h[key] = value.split('T')[0],
303
+ _h));
304
+ break;
305
+ case 'dateBefore':
306
+ queryBuilder.andWhere("".concat(key !== 'expiration' && key !== 'start'
307
+ ? 'DATE(CONVERT_TZ('
308
+ : '', " ").concat(accessKey, " ").concat(key !== 'expiration' && key !== 'start'
309
+ ? ", '+00:00', '".concat(timezone, "'))")
310
+ : '', " < :").concat(key), (_j = {},
311
+ _j[key] = value.split('T')[0],
312
+ _j));
313
+ break;
314
+ case 'dateAfter':
315
+ queryBuilder.andWhere("".concat(key !== 'expiration' && key !== 'start'
316
+ ? 'DATE(CONVERT_TZ('
317
+ : '', " ").concat(accessKey, " ").concat(key !== 'expiration' && key !== 'start'
318
+ ? ", '+00:00', '".concat(timezone, "'))")
319
+ : '', " > :").concat(key), (_k = {},
320
+ _k[key] = value.split('T')[0],
321
+ _k));
322
+ break;
323
+ default:
324
+ break;
325
+ }
326
+ }
327
+ });
328
+ // DOC: Ordenamiento
329
+ if (lazyEvent.sortField) {
330
+ order = lazyEvent.sortOrder === 1 ? 'ASC' : 'DESC';
331
+ if (lazyEvent.sortField === 'local.name') {
332
+ queryBuilder.orderBy("local.name", order);
333
+ }
334
+ else {
335
+ if (lazyEvent.sortField === 'typeText') {
336
+ queryBuilder.orderBy("discount_code_user.type", order);
337
+ }
338
+ else if (lazyEvent.sortField === 'status') {
339
+ queryBuilder.orderBy("discount_code_user.status", order);
340
+ }
341
+ else {
342
+ queryBuilder.orderBy("discount_code_user.".concat(lazyEvent.sortField), order);
343
+ }
344
+ }
345
+ }
346
+ return [4 /*yield*/, queryBuilder.getManyAndCount()];
347
+ case 1:
348
+ _c = _d.sent(), discountsCodeUser = _c[0], totalRecords = _c[1];
349
+ return [2 /*return*/, {
350
+ data: discountsCodeUser,
351
+ totalRecords: totalRecords,
352
+ }];
353
+ }
354
+ });
355
+ });
356
+ };
172
357
  CustomRepository.prototype.anyOtherRepository = function (args) {
173
358
  return __awaiter(this, void 0, void 0, function () {
174
359
  return __generator(this, function (_a) {
@@ -24,4 +24,7 @@ export interface IPropsQueryVerifyLocal {
24
24
  filters: any;
25
25
  };
26
26
  }
27
+ export interface IPropsDiscountUserOrCompany extends IPropsQueryVerifyLocal {
28
+ company?: number;
29
+ }
27
30
  export type IType = 'mysql' | 'mariadb';
package/dist/utils.d.ts CHANGED
@@ -1 +1,3 @@
1
1
  export declare function getStatusVerifyLocalNumber(status: string): any;
2
+ export declare function getStatusBasic(status: string): any;
3
+ export declare function getSeverityNameDiscountType(type: string): any;
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getStatusVerifyLocalNumber = void 0;
3
+ exports.getSeverityNameDiscountType = exports.getStatusBasic = exports.getStatusVerifyLocalNumber = void 0;
4
4
  function getStatusVerifyLocalNumber(status) {
5
5
  var statuses = {
6
6
  'Pending approval': 1,
@@ -13,3 +13,31 @@ function getStatusVerifyLocalNumber(status) {
13
13
  return statuses[status];
14
14
  }
15
15
  exports.getStatusVerifyLocalNumber = getStatusVerifyLocalNumber;
16
+ function getStatusBasic(status) {
17
+ var statuses = {
18
+ Active: 1,
19
+ active: 1,
20
+ Inactive: 0,
21
+ inactive: 0,
22
+ Activo: 1,
23
+ activo: 1,
24
+ Inactivo: 0,
25
+ inactivo: 0,
26
+ };
27
+ return statuses[status] || status;
28
+ }
29
+ exports.getStatusBasic = getStatusBasic;
30
+ function getSeverityNameDiscountType(type) {
31
+ var types = {
32
+ Percentage: 1,
33
+ percentage: 1,
34
+ Porcentaje: 1,
35
+ porcentaje: 1,
36
+ Moneda: 2,
37
+ moneda: 2,
38
+ Currency: 1,
39
+ currency: 1,
40
+ };
41
+ return types[type] || type;
42
+ }
43
+ exports.getSeverityNameDiscountType = getSeverityNameDiscountType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "2.7.3",
3
+ "version": "2.7.4",
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,6 +1,14 @@
1
1
  import { DataSource, EntityTarget, Repository, ObjectLiteral } from 'typeorm'
2
- import { IPropsQueryVerifyLocal } from './interfaces'
3
- import { getStatusVerifyLocalNumber } from './utils'
2
+ import {
3
+ IPropsDiscountUserOrCompany,
4
+ IPropsQueryVerifyLocal,
5
+ } from './interfaces'
6
+ import {
7
+ getSeverityNameDiscountType,
8
+ getStatusBasic,
9
+ getStatusVerifyLocalNumber,
10
+ } from './utils'
11
+ import { getTimeZone, getTimezoneOffset, Partner } from '.'
4
12
 
5
13
  export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
6
14
  constructor(target: EntityTarget<T>, dataSource: DataSource) {
@@ -147,6 +155,240 @@ export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
147
155
  }
148
156
  }
149
157
 
158
+ async getDiscountCodeUser({
159
+ status,
160
+ company,
161
+ lazyEvent,
162
+ }: IPropsDiscountUserOrCompany) {
163
+ // const response = await getRepository.getVerifyLocals({ status: 1, lazyEvent })
164
+ const timezone = getTimezoneOffset(getTimeZone())
165
+
166
+ const queryBuilder = this.createQueryBuilder('discount_code_user')
167
+ .skip(lazyEvent.first)
168
+ .take(lazyEvent.rows)
169
+
170
+ // DOC: Filtro global
171
+ if (lazyEvent.filters['global'] && lazyEvent.filters['global'].value) {
172
+ const globalValue = `%${lazyEvent.filters['global'].value.toLowerCase()}%`
173
+ queryBuilder.andWhere(
174
+ 'LOWER(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',
175
+ {
176
+ globalValue:
177
+ globalValue ||
178
+ getStatusBasic(lazyEvent.filters['global'].value.toLowerCase()) ||
179
+ getSeverityNameDiscountType(
180
+ lazyEvent.filters['global'].value.toLowerCase()
181
+ ),
182
+ }
183
+ )
184
+ }
185
+
186
+ // DOC: Filtro por estado FILTRO POR DEFECTO
187
+ if (status !== null && status >= 0) {
188
+ queryBuilder.andWhere('discount_code_user.status = :status', {
189
+ status: status,
190
+ })
191
+ }
192
+
193
+ // DOC: Filtro por company FILTRO POR DEFECTO
194
+ if (!!company && company >= 0) {
195
+ queryBuilder.andWhere('discount_code_user.company = :company', {
196
+ company: company,
197
+ })
198
+ }
199
+
200
+ // DOC: Aplicación de filtros globales para las columnas de las tablas.
201
+ const filters = lazyEvent.filters
202
+ Object.keys(filters).forEach((key) => {
203
+ let value = filters[key].value
204
+ if (
205
+ (Array.isArray(value) && value.length > 0) ||
206
+ (!Array.isArray(value) && value && key !== 'global')
207
+ ) {
208
+ const matchMode = filters[key].matchMode
209
+ if (!Array.isArray(value) && value) {
210
+ value = filters[key].value.toLowerCase()
211
+ }
212
+ const accessKey =
213
+ key.split('.').length > 1 ? `${key}` : `discount_code_user.${key}`
214
+
215
+ switch (matchMode) {
216
+ case 'custom':
217
+ if (
218
+ (key === 'number_of_times_used' || key === 'use_limit') &&
219
+ matchMode === 'custom'
220
+ ) {
221
+ const [from, to] = value || [null, null]
222
+
223
+ if (from !== null && to === null) {
224
+ queryBuilder.andWhere(`discount_code_user.${key} >= :from`, {
225
+ from,
226
+ })
227
+ } else if (from === null && to !== null) {
228
+ queryBuilder.andWhere(`discount_code_user.${key} <= :to`, {
229
+ to,
230
+ })
231
+ } else if (from !== null && to !== null) {
232
+ queryBuilder.andWhere(
233
+ `discount_code_user.${key} BETWEEN :from AND :to`,
234
+ { from, to }
235
+ )
236
+ }
237
+ }
238
+ break
239
+ case 'contains':
240
+ queryBuilder.andWhere(`${accessKey} LIKE :${key}`, {
241
+ [key]: `%${value}%`,
242
+ })
243
+ break
244
+ case 'startsWith':
245
+ queryBuilder.andWhere(`${accessKey} LIKE :${key}`, {
246
+ [key]: `${value}%`,
247
+ })
248
+ break
249
+ case 'endsWith':
250
+ queryBuilder.andWhere(`${accessKey} LIKE :${key}`, {
251
+ [key]: `%${value}`,
252
+ })
253
+ break
254
+ case 'equals':
255
+ if (key === 'status') {
256
+ queryBuilder.andWhere('discount_code_user.status = :status', {
257
+ status: getStatusBasic(filters[key].value ?? ''),
258
+ })
259
+ } else if (key === 'typeText') {
260
+ queryBuilder.andWhere('discount_code_user.type = :type', {
261
+ type: getSeverityNameDiscountType(filters[key].value ?? ''),
262
+ })
263
+ } else if (key === 'updated_by') {
264
+ const updatedByIds = filters[key].value.map(
265
+ (element: Partner) => element.id
266
+ )
267
+
268
+ if (updatedByIds.length > 0) {
269
+ queryBuilder.andWhere(
270
+ 'discount_code_user.updated_by IN (:...updatedByIds)',
271
+ {
272
+ updatedByIds,
273
+ }
274
+ )
275
+ }
276
+ } else {
277
+ queryBuilder.andWhere(`${accessKey} = :${key}`, {
278
+ [key]: value,
279
+ })
280
+ }
281
+ break
282
+ case 'notContains':
283
+ queryBuilder.andWhere(`${accessKey} NOT LIKE :${key}`, {
284
+ [key]: `%${value}%`,
285
+ })
286
+ break
287
+ case 'notEquals':
288
+ queryBuilder.andWhere(`${accessKey} != :${key}`, {
289
+ [key]: value,
290
+ })
291
+ break
292
+ case 'dateIs':
293
+ queryBuilder.andWhere(
294
+ `${
295
+ key !== 'expiration' && key !== 'start'
296
+ ? 'DATE(CONVERT_TZ('
297
+ : ''
298
+ } ${accessKey} ${
299
+ key !== 'expiration' && key !== 'start'
300
+ ? `, '+00:00', '${timezone}'))`
301
+ : ''
302
+ } = :${key}`,
303
+ {
304
+ [key]: value.split('T')[0],
305
+ }
306
+ )
307
+ break
308
+ case 'dateIsNot':
309
+ queryBuilder.andWhere(
310
+ `${
311
+ key !== 'expiration' && key !== 'start'
312
+ ? 'DATE(CONVERT_TZ('
313
+ : ''
314
+ } ${accessKey} ${
315
+ key !== 'expiration' && key !== 'start'
316
+ ? `, '+00:00', '${timezone}'))`
317
+ : ''
318
+ } != :${key}`,
319
+ {
320
+ [key]: value.split('T')[0],
321
+ }
322
+ )
323
+ break
324
+ case 'dateBefore':
325
+ queryBuilder.andWhere(
326
+ `${
327
+ key !== 'expiration' && key !== 'start'
328
+ ? 'DATE(CONVERT_TZ('
329
+ : ''
330
+ } ${accessKey} ${
331
+ key !== 'expiration' && key !== 'start'
332
+ ? `, '+00:00', '${timezone}'))`
333
+ : ''
334
+ } < :${key}`,
335
+ {
336
+ [key]: value.split('T')[0],
337
+ }
338
+ )
339
+ break
340
+ case 'dateAfter':
341
+ queryBuilder.andWhere(
342
+ `${
343
+ key !== 'expiration' && key !== 'start'
344
+ ? 'DATE(CONVERT_TZ('
345
+ : ''
346
+ } ${accessKey} ${
347
+ key !== 'expiration' && key !== 'start'
348
+ ? `, '+00:00', '${timezone}'))`
349
+ : ''
350
+ } > :${key}`,
351
+ {
352
+ [key]: value.split('T')[0],
353
+ }
354
+ )
355
+ break
356
+ default:
357
+ break
358
+ }
359
+ }
360
+ })
361
+
362
+ // DOC: Ordenamiento
363
+ if (lazyEvent.sortField) {
364
+ const order = lazyEvent.sortOrder === 1 ? 'ASC' : 'DESC'
365
+
366
+ if (lazyEvent.sortField === 'local.name') {
367
+ queryBuilder.orderBy(`local.name`, order)
368
+ } else {
369
+ if (lazyEvent.sortField === 'typeText') {
370
+ queryBuilder.orderBy(`discount_code_user.type`, order)
371
+ } else if (lazyEvent.sortField === 'status') {
372
+ queryBuilder.orderBy(`discount_code_user.status`, order)
373
+ } else {
374
+ queryBuilder.orderBy(
375
+ `discount_code_user.${lazyEvent.sortField}`,
376
+ order
377
+ )
378
+ }
379
+ }
380
+ }
381
+
382
+ // DOC: Ejecutar la consulta
383
+ const [discountsCodeUser, totalRecords] =
384
+ await queryBuilder.getManyAndCount()
385
+
386
+ return {
387
+ data: discountsCodeUser,
388
+ totalRecords,
389
+ }
390
+ }
391
+
150
392
  async anyOtherRepository(args: any) {
151
393
  // Implementa otro método personalizado aquí
152
394
  }
package/src/interfaces.ts CHANGED
@@ -28,4 +28,8 @@ export interface IPropsQueryVerifyLocal {
28
28
  }
29
29
  }
30
30
 
31
+ export interface IPropsDiscountUserOrCompany extends IPropsQueryVerifyLocal {
32
+ company?: number
33
+ }
34
+
31
35
  export type IType = 'mysql' | 'mariadb'
package/src/utils.ts CHANGED
@@ -9,3 +9,31 @@ export function getStatusVerifyLocalNumber(status: string) {
9
9
  }
10
10
  return statuses[status]
11
11
  }
12
+
13
+ export function getStatusBasic(status: string) {
14
+ const statuses: any = {
15
+ Active: 1,
16
+ active: 1,
17
+ Inactive: 0,
18
+ inactive: 0,
19
+ Activo: 1,
20
+ activo: 1,
21
+ Inactivo: 0,
22
+ inactivo: 0,
23
+ }
24
+ return statuses[status] || status
25
+ }
26
+
27
+ export function getSeverityNameDiscountType(type: string) {
28
+ const types: any = {
29
+ Percentage: 1,
30
+ percentage: 1,
31
+ Porcentaje: 1,
32
+ porcentaje: 1,
33
+ Moneda: 2,
34
+ moneda: 2,
35
+ Currency: 1,
36
+ currency: 1,
37
+ }
38
+ return types[type] || type
39
+ }