test-entity-library-asm 2.3.2 → 2.3.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,15 +1,7 @@
1
1
  import { DataSource, EntityTarget, Repository, ObjectLiteral } from 'typeorm';
2
2
  export declare class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
3
3
  constructor(target: EntityTarget<T>, dataSource: DataSource);
4
- getVerifyLocals2(status: number | null, page: number, pageSize: number, filters: any): Promise<{
5
- data: T[];
6
- total: number;
7
- page: number;
8
- pageSize: number;
9
- totalPages: number;
10
- }>;
11
- getVerifyLocals(status: number | null, cursor: string | null, // The cursor, typically an encoded value like an ID or timestamp
12
- limit: number, filters: any): Promise<{
4
+ getVerifyLocals(status: number | null, cursor: string | null, limit: number, filters: any): Promise<{
13
5
  data: T[];
14
6
  nextCursor: string | null;
15
7
  }>;
@@ -58,81 +58,9 @@ var CustomRepository = /** @class */ (function (_super) {
58
58
  function CustomRepository(target, dataSource) {
59
59
  return _super.call(this, target, dataSource.manager) || this;
60
60
  }
61
- CustomRepository.prototype.getVerifyLocals2 = function (status, page, pageSize, filters) {
61
+ CustomRepository.prototype.getVerifyLocals = function (status, cursor, limit, filters) {
62
62
  return __awaiter(this, void 0, void 0, function () {
63
- var queryBuilder, globalValue, _a, data, total;
64
- return __generator(this, function (_b) {
65
- switch (_b.label) {
66
- case 0:
67
- queryBuilder = this.createQueryBuilder('entity')
68
- .skip((page - 1) * pageSize)
69
- .take(pageSize);
70
- if (status !== null && status >= 0) {
71
- queryBuilder.andWhere('entity.status = :status', { status: status });
72
- }
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 });
79
- }
80
- Object.keys(filters).forEach(function (key) {
81
- var _a, _b, _c, _d;
82
- if (key !== 'global' && filters[key].constraints) {
83
- var filter = filters[key];
84
- var value = filter.constraints[0].value;
85
- var matchMode = filter.constraints[0].matchMode;
86
- if (value !== null) {
87
- var jsonPath = key
88
- .split('.')
89
- .map(function (segment) { return "$.".concat(segment); })
90
- .join('');
91
- switch (matchMode) {
92
- case 'startsWith':
93
- queryBuilder.andWhere("JSON_EXTRACT(entity.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\") LIKE :").concat(key), (_a = {},
94
- _a[key] = "".concat(value, "%"),
95
- _a));
96
- break;
97
- case 'contains':
98
- queryBuilder.andWhere("JSON_EXTRACT(entity.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\") LIKE :").concat(key), (_b = {},
99
- _b[key] = "%".concat(value, "%"),
100
- _b));
101
- break;
102
- case 'equals':
103
- queryBuilder.andWhere("JSON_EXTRACT(entity.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\") = :").concat(key), (_c = {},
104
- _c[key] = value,
105
- _c));
106
- break;
107
- case 'dateIs':
108
- queryBuilder.andWhere("DATE(JSON_EXTRACT(entity.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\")) = :").concat(key), (_d = {},
109
- _d[key] = value,
110
- _d));
111
- break;
112
- default:
113
- break;
114
- }
115
- }
116
- }
117
- });
118
- return [4 /*yield*/, queryBuilder.getManyAndCount()];
119
- case 1:
120
- _a = _b.sent(), data = _a[0], total = _a[1];
121
- return [2 /*return*/, {
122
- data: data,
123
- total: total,
124
- page: page,
125
- pageSize: pageSize,
126
- totalPages: Math.ceil(total / pageSize),
127
- }];
128
- }
129
- });
130
- });
131
- };
132
- CustomRepository.prototype.getVerifyLocals = function (status, cursor, // The cursor, typically an encoded value like an ID or timestamp
133
- limit, filters) {
134
- return __awaiter(this, void 0, void 0, function () {
135
- var queryBuilder, globalValue, decodedCursor, results, nextCursor;
63
+ var queryBuilder, globalValue, decodedCursor, cursorDate, results, nextCursor;
136
64
  var _a;
137
65
  return __generator(this, function (_b) {
138
66
  switch (_b.label) {
@@ -151,8 +79,10 @@ var CustomRepository = /** @class */ (function (_super) {
151
79
  }
152
80
  if (cursor) {
153
81
  decodedCursor = Buffer.from(cursor, 'base64').toString('ascii');
82
+ cursorDate = new Date(decodedCursor) // Convert the decoded cursor to a Date object
83
+ ;
154
84
  queryBuilder.andWhere('entity.created > :cursor', {
155
- cursor: decodedCursor,
85
+ cursor: cursorDate.toISOString(),
156
86
  });
157
87
  }
158
88
  queryBuilder.orderBy('entity.created', 'ASC');
@@ -161,8 +91,8 @@ var CustomRepository = /** @class */ (function (_super) {
161
91
  results = _b.sent();
162
92
  nextCursor = results.length > limit ? (_a = results.pop()) === null || _a === void 0 ? void 0 : _a.created : null;
163
93
  return [2 /*return*/, {
164
- data: results,
165
- nextCursor: nextCursor
94
+ data: results.slice(0, limit), // Return only the requested number of results
95
+ nextCursor: nextCursor && nextCursor instanceof Date
166
96
  ? Buffer.from(nextCursor.toISOString()).toString('base64')
167
97
  : null,
168
98
  }];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "2.3.2",
3
+ "version": "2.3.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",
@@ -5,104 +5,9 @@ export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
5
5
  super(target, dataSource.manager)
6
6
  }
7
7
 
8
- async getVerifyLocals2(
9
- status: number | null,
10
- page: number,
11
- pageSize: number,
12
- filters: any
13
- ) {
14
- const queryBuilder = this.createQueryBuilder('entity')
15
- .skip((page - 1) * pageSize)
16
- .take(pageSize)
17
-
18
- if (status !== null && status >= 0) {
19
- queryBuilder.andWhere('entity.status = :status', { status })
20
- }
21
-
22
- if (filters['global'] && filters['global'].value) {
23
- const globalValue = `%${filters['global'].value}%`
24
- queryBuilder.andWhere(
25
- '(JSON_EXTRACT(entity.local_information, "$.name") LIKE :globalValue ' +
26
- 'OR JSON_EXTRACT(entity.local_information, "$.square.address") LIKE :globalValue ' +
27
- 'OR JSON_EXTRACT(entity.local_information, "$.address.formatted_address") LIKE :globalValue ' +
28
- 'OR entity.status LIKE :globalValue)',
29
- { globalValue }
30
- )
31
- }
32
-
33
- Object.keys(filters).forEach((key) => {
34
- if (key !== 'global' && filters[key].constraints) {
35
- const filter = filters[key]
36
- const value = filter.constraints[0].value
37
- const matchMode = filter.constraints[0].matchMode
38
-
39
- if (value !== null) {
40
- const jsonPath = key
41
- .split('.')
42
- .map((segment) => `$.${segment}`)
43
- .join('')
44
- switch (matchMode) {
45
- case 'startsWith':
46
- queryBuilder.andWhere(
47
- `JSON_EXTRACT(entity.${
48
- key.split('.')[0]
49
- }, "${jsonPath}") LIKE :${key}`,
50
- {
51
- [key]: `${value}%`,
52
- }
53
- )
54
- break
55
- case 'contains':
56
- queryBuilder.andWhere(
57
- `JSON_EXTRACT(entity.${
58
- key.split('.')[0]
59
- }, "${jsonPath}") LIKE :${key}`,
60
- {
61
- [key]: `%${value}%`,
62
- }
63
- )
64
- break
65
- case 'equals':
66
- queryBuilder.andWhere(
67
- `JSON_EXTRACT(entity.${
68
- key.split('.')[0]
69
- }, "${jsonPath}") = :${key}`,
70
- {
71
- [key]: value,
72
- }
73
- )
74
- break
75
- case 'dateIs':
76
- queryBuilder.andWhere(
77
- `DATE(JSON_EXTRACT(entity.${
78
- key.split('.')[0]
79
- }, "${jsonPath}")) = :${key}`,
80
- {
81
- [key]: value,
82
- }
83
- )
84
- break
85
- default:
86
- break
87
- }
88
- }
89
- }
90
- })
91
-
92
- const [data, total] = await queryBuilder.getManyAndCount()
93
-
94
- return {
95
- data,
96
- total,
97
- page,
98
- pageSize,
99
- totalPages: Math.ceil(total / pageSize),
100
- }
101
- }
102
-
103
8
  async getVerifyLocals(
104
9
  status: number | null,
105
- cursor: string | null, // The cursor, typically an encoded value like an ID or timestamp
10
+ cursor: string | null,
106
11
  limit: number,
107
12
  filters: any
108
13
  ): Promise<{ data: T[]; nextCursor: string | null }> {
@@ -124,10 +29,10 @@ export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
124
29
  }
125
30
 
126
31
  if (cursor) {
127
- // Decode and use the cursor for the WHERE clause
128
32
  const decodedCursor = Buffer.from(cursor, 'base64').toString('ascii')
33
+ const cursorDate = new Date(decodedCursor) // Convert the decoded cursor to a Date object
129
34
  queryBuilder.andWhere('entity.created > :cursor', {
130
- cursor: decodedCursor,
35
+ cursor: cursorDate.toISOString(),
131
36
  })
132
37
  }
133
38
 
@@ -137,10 +42,11 @@ export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
137
42
  const nextCursor = results.length > limit ? results.pop()?.created : null
138
43
 
139
44
  return {
140
- data: results,
141
- nextCursor: nextCursor
142
- ? Buffer.from(nextCursor.toISOString()).toString('base64')
143
- : null,
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
50
  }
145
51
  }
146
52