test-entity-library-asm 2.3.4 → 2.3.6

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,9 +1,10 @@
1
1
  import { DataSource, EntityTarget, Repository, ObjectLiteral } from 'typeorm';
2
+ import { IPropsQueryVerifyLocal } from './interfaces';
2
3
  export declare class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
3
4
  constructor(target: EntityTarget<T>, dataSource: DataSource);
4
- getVerifyLocals(status: number | null, cursor: string | null, limit: number, filters: any): Promise<{
5
+ getVerifyLocals({ status, lazyEvent }: IPropsQueryVerifyLocal): Promise<{
5
6
  data: T[];
6
- nextCursor: string | null;
7
+ totalRecords: number;
7
8
  }>;
8
9
  anyOtherRepository(args: any): Promise<void>;
9
10
  }
@@ -53,48 +53,116 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
53
53
  Object.defineProperty(exports, "__esModule", { value: true });
54
54
  exports.CustomRepository = void 0;
55
55
  var typeorm_1 = require("typeorm");
56
+ var utils_1 = require("./utils");
56
57
  var CustomRepository = /** @class */ (function (_super) {
57
58
  __extends(CustomRepository, _super);
58
59
  function CustomRepository(target, dataSource) {
59
60
  return _super.call(this, target, dataSource.manager) || this;
60
61
  }
61
- CustomRepository.prototype.getVerifyLocals = function (status, cursor, limit, filters) {
62
- return __awaiter(this, void 0, void 0, function () {
63
- var queryBuilder, globalValue, decodedCursor, cursorDate, results, nextCursor;
64
- var _a;
65
- return __generator(this, function (_b) {
66
- switch (_b.label) {
62
+ CustomRepository.prototype.getVerifyLocals = function (_a) {
63
+ return __awaiter(this, arguments, void 0, function (_b) {
64
+ var queryBuilder, globalValue, filters, order, jsonPath, _c, data, total;
65
+ var status = _b.status, lazyEvent = _b.lazyEvent;
66
+ return __generator(this, function (_d) {
67
+ switch (_d.label) {
67
68
  case 0:
68
- queryBuilder = this.createQueryBuilder('entity').take(limit + 1) // Fetch one more record than needed to determine if there's a next page
69
- ;
70
- if (status !== null && status >= 0) {
71
- queryBuilder.andWhere('entity.status = :status', { status: status });
69
+ queryBuilder = this.createQueryBuilder('verify_local')
70
+ .skip(lazyEvent.first)
71
+ .take(lazyEvent.rows);
72
+ if (lazyEvent.filters['global'] && lazyEvent.filters['global'].value) {
73
+ globalValue = "%".concat(lazyEvent.filters['global'].value.toLowerCase(), "%");
74
+ queryBuilder.andWhere('LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.local_information, "$.name"))) LIKE :globalValue OR LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.local_information, "$.addressElement"))) LIKE :globalValue', { globalValue: globalValue });
72
75
  }
73
- if (filters['global'] && filters['global'].value) {
74
- globalValue = "%".concat(filters['global'].value, "%");
75
- queryBuilder.andWhere('(JSON_EXTRACT(entity.local_information, "$.name") LIKE :globalValue ' +
76
- 'OR JSON_EXTRACT(entity.local_information, "$.square.address") LIKE :globalValue ' +
77
- 'OR JSON_EXTRACT(entity.local_information, "$.address.formatted_address") LIKE :globalValue ' +
78
- 'OR entity.status LIKE :globalValue)', { globalValue: globalValue });
76
+ // Filtro por estado
77
+ if (status !== null && status >= 0) {
78
+ queryBuilder.andWhere('verify_local.status = :status', { status: status });
79
79
  }
80
- if (cursor) {
81
- decodedCursor = Buffer.from(cursor, 'base64').toString('ascii');
82
- cursorDate = new Date(decodedCursor) // Convert the decoded cursor to a Date object
83
- ;
84
- queryBuilder.andWhere('entity.created > :cursor', {
85
- cursor: cursorDate.toISOString(),
86
- });
80
+ filters = lazyEvent.filters;
81
+ Object.keys(filters).forEach(function (key) {
82
+ var _a, _b, _c, _d, _e, _f;
83
+ var _g;
84
+ if (filters[key] && filters[key].value) {
85
+ var matchMode = filters[key].matchMode;
86
+ var value = filters[key].value;
87
+ if (key === 'status') {
88
+ queryBuilder.andWhere('verify_local.status = :status', {
89
+ status: (0, utils_1.getStatusVerifyLocalNumber)((_g = filters[key].value) !== null && _g !== void 0 ? _g : ''),
90
+ });
91
+ }
92
+ else if (key === 'created') {
93
+ switch (matchMode) {
94
+ case 'dateIs':
95
+ queryBuilder.andWhere("DATE(verify_local.created) = :created", {
96
+ created: value,
97
+ });
98
+ break;
99
+ case 'dateBefore':
100
+ queryBuilder.andWhere("DATE(verify_local.created) < :created", {
101
+ created: value,
102
+ });
103
+ break;
104
+ case 'dateAfter':
105
+ queryBuilder.andWhere("DATE(verify_local.created) > :created", {
106
+ created: value,
107
+ });
108
+ break;
109
+ default:
110
+ break;
111
+ }
112
+ }
113
+ else if (key !== 'global') {
114
+ var jsonPath = key
115
+ .split('.')
116
+ .slice(1)
117
+ .map(function (segment) { return "$.".concat(segment); })
118
+ .join('');
119
+ var paramKey = key.split('.')[1];
120
+ switch (matchMode) {
121
+ case 'contains':
122
+ queryBuilder.andWhere("LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\"))) LIKE :").concat(paramKey), (_a = {}, _a[paramKey] = "%".concat(value, "%"), _a));
123
+ break;
124
+ case 'startsWith':
125
+ queryBuilder.andWhere("LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\"))) LIKE :").concat(paramKey), (_b = {}, _b[paramKey] = "".concat(value, "%"), _b));
126
+ break;
127
+ case 'notContains':
128
+ queryBuilder.andWhere("LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\"))) NOT LIKE :").concat(paramKey), (_c = {}, _c[paramKey] = "%".concat(value, "%"), _c));
129
+ break;
130
+ case 'endsWith':
131
+ queryBuilder.andWhere("LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\"))) LIKE :").concat(paramKey), (_d = {}, _d[paramKey] = "%".concat(value), _d));
132
+ break;
133
+ case 'equals':
134
+ queryBuilder.andWhere("LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\"))) = :").concat(paramKey), (_e = {}, _e[paramKey] = value, _e));
135
+ break;
136
+ case 'notEquals':
137
+ queryBuilder.andWhere("LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\"))) != :").concat(paramKey), (_f = {}, _f[paramKey] = value, _f));
138
+ break;
139
+ default:
140
+ break;
141
+ }
142
+ }
143
+ }
144
+ });
145
+ // Ordenamiento
146
+ if (lazyEvent.sortField) {
147
+ order = lazyEvent.sortOrder === 1 ? 'ASC' : 'DESC';
148
+ if (lazyEvent.sortField.startsWith('local_information.')) {
149
+ jsonPath = lazyEvent.sortField
150
+ .split('.')
151
+ .slice(1)
152
+ .map(function (segment) { return "$.".concat(segment); })
153
+ .join('');
154
+ queryBuilder.orderBy("LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.local_information, '".concat(jsonPath, "')))"), order);
155
+ }
156
+ else {
157
+ queryBuilder.orderBy(lazyEvent.sortField, order);
158
+ }
87
159
  }
88
- queryBuilder.orderBy('entity.created', 'ASC');
89
- return [4 /*yield*/, queryBuilder.getMany()];
160
+ return [4 /*yield*/, queryBuilder.getManyAndCount()];
90
161
  case 1:
91
- results = _b.sent();
92
- nextCursor = results.length > limit ? (_a = results.pop()) === null || _a === void 0 ? void 0 : _a.created : null;
162
+ _c = _d.sent(), data = _c[0], total = _c[1];
93
163
  return [2 /*return*/, {
94
- data: results.slice(0, limit), // Return only the requested number of results
95
- nextCursor: nextCursor && nextCursor instanceof Date
96
- ? Buffer.from(nextCursor.toISOString()).toString('base64')
97
- : null,
164
+ data: data,
165
+ totalRecords: total,
98
166
  }];
99
167
  }
100
168
  });
@@ -43,3 +43,4 @@ export { AuthenticationCredential } from './entities/AuthenticationCredential';
43
43
  export { PosSystem } from './entities/PosSystem';
44
44
  export { VerifyLocal } from './entities/VerifyLocal';
45
45
  export { CustomRepository } from './CustomRepository';
46
+ export * from './utils';
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.CustomRepository = exports.VerifyLocal = exports.PosSystem = exports.AuthenticationCredential = exports.BusinessType = exports.LocalsCompany = exports.UserAddress = exports.User = exports.TypeMeasureIngredient = exports.TerminalSession = exports.Terminal = exports.Square = exports.RequestStatus = exports.RequestProductGroupComplement = exports.RequestProduct = exports.Request = exports.Region = exports.ProductTopping = exports.ProductIngredient = exports.ProductGroupComplement = exports.ProductGroup = exports.Product = exports.Plan = exports.PaymentMethod = exports.PartnerRole = exports.PartnerPermission = exports.PartnerNotification = exports.Partner = exports.MasterRole = exports.MasterPermission = exports.Master = exports.LocalQualification = exports.Local = exports.DiscountCodeUser = exports.DiscountCodeCompany = exports.Day = exports.Country = exports.Configuration = exports.Company = exports.CodeRedemptionHistoryUser = exports.CodeRedemptionHistoryCompany = exports.City = exports.ScheduleCategory = exports.Category = exports.BusinessTypeProduct = void 0;
4
18
  var BusinessTypeProduct_1 = require("./entities/BusinessTypeProduct");
@@ -91,3 +105,4 @@ var VerifyLocal_1 = require("./entities/VerifyLocal");
91
105
  Object.defineProperty(exports, "VerifyLocal", { enumerable: true, get: function () { return VerifyLocal_1.VerifyLocal; } });
92
106
  var CustomRepository_1 = require("./CustomRepository");
93
107
  Object.defineProperty(exports, "CustomRepository", { enumerable: true, get: function () { return CustomRepository_1.CustomRepository; } });
108
+ __exportStar(require("./utils"), exports);
@@ -13,4 +13,15 @@ export interface IDataBaseSource {
13
13
  synchronize: boolean;
14
14
  entitiesRoute?: string;
15
15
  }
16
+ export interface IPropsQueryVerifyLocal {
17
+ status: number;
18
+ lazyEvent: {
19
+ first: number;
20
+ rows: number;
21
+ page: number;
22
+ sortField: any;
23
+ sortOrder: any;
24
+ filters: any;
25
+ };
26
+ }
16
27
  export type IType = 'mysql' | 'mariadb';
@@ -0,0 +1 @@
1
+ export declare function getStatusVerifyLocalNumber(status: string): any;
package/dist/utils.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getStatusVerifyLocalNumber = void 0;
4
+ function getStatusVerifyLocalNumber(status) {
5
+ var statuses = {
6
+ 'Pending approval': 1,
7
+ Approved: 2,
8
+ Rejected: 3,
9
+ 'Pendiente aprobación': 1,
10
+ Aprobado: 3,
11
+ Rechazado: 2,
12
+ };
13
+ return statuses[status];
14
+ }
15
+ exports.getStatusVerifyLocalNumber = getStatusVerifyLocalNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "2.3.4",
3
+ "version": "2.3.6",
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,52 +1,148 @@
1
1
  import { DataSource, EntityTarget, Repository, ObjectLiteral } from 'typeorm'
2
+ import { IPropsQueryVerifyLocal } from './interfaces'
3
+ import { getStatusVerifyLocalNumber } from './utils'
2
4
 
3
5
  export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
4
6
  constructor(target: EntityTarget<T>, dataSource: DataSource) {
5
7
  super(target, dataSource.manager)
6
8
  }
7
9
 
8
- async getVerifyLocals(
9
- status: number | null,
10
- cursor: string | null,
11
- limit: number,
12
- filters: any
13
- ): Promise<{ data: T[]; nextCursor: string | null }> {
14
- const queryBuilder = this.createQueryBuilder('entity').take(limit + 1) // Fetch one more record than needed to determine if there's a next page
10
+ async getVerifyLocals({ status, lazyEvent }: IPropsQueryVerifyLocal) {
11
+ const queryBuilder = this.createQueryBuilder('verify_local')
12
+ .skip(lazyEvent.first)
13
+ .take(lazyEvent.rows)
15
14
 
16
- if (status !== null && status >= 0) {
17
- queryBuilder.andWhere('entity.status = :status', { status })
18
- }
19
-
20
- if (filters['global'] && filters['global'].value) {
21
- const globalValue = `%${filters['global'].value}%`
15
+ if (lazyEvent.filters['global'] && lazyEvent.filters['global'].value) {
16
+ const globalValue = `%${lazyEvent.filters['global'].value.toLowerCase()}%`
22
17
  queryBuilder.andWhere(
23
- '(JSON_EXTRACT(entity.local_information, "$.name") LIKE :globalValue ' +
24
- 'OR JSON_EXTRACT(entity.local_information, "$.square.address") LIKE :globalValue ' +
25
- 'OR JSON_EXTRACT(entity.local_information, "$.address.formatted_address") LIKE :globalValue ' +
26
- 'OR entity.status LIKE :globalValue)',
18
+ 'LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.local_information, "$.name"))) LIKE :globalValue OR LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.local_information, "$.addressElement"))) LIKE :globalValue',
27
19
  { globalValue }
28
20
  )
29
21
  }
30
22
 
31
- if (cursor) {
32
- const decodedCursor = Buffer.from(cursor, 'base64').toString('ascii')
33
- const cursorDate = new Date(decodedCursor) // Convert the decoded cursor to a Date object
34
- queryBuilder.andWhere('entity.created > :cursor', {
35
- cursor: cursorDate.toISOString(),
36
- })
23
+ // Filtro por estado
24
+ if (status !== null && status >= 0) {
25
+ queryBuilder.andWhere('verify_local.status = :status', { status })
37
26
  }
38
27
 
39
- queryBuilder.orderBy('entity.created', 'ASC')
28
+ // Aplicación de filtros
29
+ const filters = lazyEvent.filters
30
+ Object.keys(filters).forEach((key) => {
31
+ if (filters[key] && filters[key].value) {
32
+ const matchMode = filters[key].matchMode
33
+ const value = filters[key].value
34
+
35
+ if (key === 'status') {
36
+ queryBuilder.andWhere('verify_local.status = :status', {
37
+ status: getStatusVerifyLocalNumber(filters[key].value ?? ''),
38
+ })
39
+ } else if (key === 'created') {
40
+ switch (matchMode) {
41
+ case 'dateIs':
42
+ queryBuilder.andWhere(`DATE(verify_local.created) = :created`, {
43
+ created: value,
44
+ })
45
+ break
46
+ case 'dateBefore':
47
+ queryBuilder.andWhere(`DATE(verify_local.created) < :created`, {
48
+ created: value,
49
+ })
50
+ break
51
+ case 'dateAfter':
52
+ queryBuilder.andWhere(`DATE(verify_local.created) > :created`, {
53
+ created: value,
54
+ })
55
+ break
56
+ default:
57
+ break
58
+ }
59
+ } else if (key !== 'global') {
60
+ const jsonPath = key
61
+ .split('.')
62
+ .slice(1)
63
+ .map((segment) => `$.${segment}`)
64
+ .join('')
65
+ const paramKey = key.split('.')[1]
66
+
67
+ switch (matchMode) {
68
+ case 'contains':
69
+ queryBuilder.andWhere(
70
+ `LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.${
71
+ key.split('.')[0]
72
+ }, "${jsonPath}"))) LIKE :${paramKey}`,
73
+ { [paramKey]: `%${value}%` }
74
+ )
75
+ break
76
+ case 'startsWith':
77
+ queryBuilder.andWhere(
78
+ `LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.${
79
+ key.split('.')[0]
80
+ }, "${jsonPath}"))) LIKE :${paramKey}`,
81
+ { [paramKey]: `${value}%` }
82
+ )
83
+ break
84
+ case 'notContains':
85
+ queryBuilder.andWhere(
86
+ `LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.${
87
+ key.split('.')[0]
88
+ }, "${jsonPath}"))) NOT LIKE :${paramKey}`,
89
+ { [paramKey]: `%${value}%` }
90
+ )
91
+ break
92
+ case 'endsWith':
93
+ queryBuilder.andWhere(
94
+ `LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.${
95
+ key.split('.')[0]
96
+ }, "${jsonPath}"))) LIKE :${paramKey}`,
97
+ { [paramKey]: `%${value}` }
98
+ )
99
+ break
100
+ case 'equals':
101
+ queryBuilder.andWhere(
102
+ `LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.${
103
+ key.split('.')[0]
104
+ }, "${jsonPath}"))) = :${paramKey}`,
105
+ { [paramKey]: value }
106
+ )
107
+ break
108
+ case 'notEquals':
109
+ queryBuilder.andWhere(
110
+ `LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.${
111
+ key.split('.')[0]
112
+ }, "${jsonPath}"))) != :${paramKey}`,
113
+ { [paramKey]: value }
114
+ )
115
+ break
116
+ default:
117
+ break
118
+ }
119
+ }
120
+ }
121
+ })
122
+
123
+ // Ordenamiento
124
+ if (lazyEvent.sortField) {
125
+ const order = lazyEvent.sortOrder === 1 ? 'ASC' : 'DESC'
126
+ if (lazyEvent.sortField.startsWith('local_information.')) {
127
+ const jsonPath = lazyEvent.sortField
128
+ .split('.')
129
+ .slice(1)
130
+ .map((segment: any) => `$.${segment}`)
131
+ .join('')
132
+ queryBuilder.orderBy(
133
+ `LOWER(JSON_UNQUOTE(JSON_EXTRACT(verify_local.local_information, '${jsonPath}')))`,
134
+ order
135
+ )
136
+ } else {
137
+ queryBuilder.orderBy(lazyEvent.sortField, order)
138
+ }
139
+ }
40
140
 
41
- const results = await queryBuilder.getMany()
42
- const nextCursor = results.length > limit ? results.pop()?.created : null
141
+ const [data, total] = await queryBuilder.getManyAndCount()
43
142
 
44
143
  return {
45
- data: results.slice(0, limit), // Return only the requested number of results
46
- nextCursor:
47
- nextCursor && nextCursor instanceof Date
48
- ? Buffer.from(nextCursor.toISOString()).toString('base64')
49
- : null,
144
+ data,
145
+ totalRecords: total,
50
146
  }
51
147
  }
52
148
 
@@ -44,3 +44,4 @@ export { PosSystem } from './entities/PosSystem'
44
44
  export { VerifyLocal } from './entities/VerifyLocal'
45
45
 
46
46
  export { CustomRepository } from './CustomRepository'
47
+ export * from './utils'
package/src/interfaces.ts CHANGED
@@ -16,4 +16,16 @@ export interface IDataBaseSource {
16
16
  entitiesRoute?: string
17
17
  }
18
18
 
19
+ export interface IPropsQueryVerifyLocal {
20
+ status: number
21
+ lazyEvent: {
22
+ first: number
23
+ rows: number
24
+ page: number
25
+ sortField: any
26
+ sortOrder: any
27
+ filters: any
28
+ }
29
+ }
30
+
19
31
  export type IType = 'mysql' | 'mariadb'
package/src/utils.ts ADDED
@@ -0,0 +1,11 @@
1
+ export function getStatusVerifyLocalNumber(status: string) {
2
+ const statuses: any = {
3
+ 'Pending approval': 1,
4
+ Approved: 2,
5
+ Rejected: 3,
6
+ 'Pendiente aprobación': 1,
7
+ Aprobado: 3,
8
+ Rechazado: 2,
9
+ }
10
+ return statuses[status]
11
+ }