test-entity-library-asm 2.3.1 → 2.3.2

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,12 +1,17 @@
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
- getVerifyLocals(status: number | null, page: number, pageSize: number, filters: any): Promise<{
4
+ getVerifyLocals2(status: number | null, page: number, pageSize: number, filters: any): Promise<{
5
5
  data: T[];
6
6
  total: number;
7
7
  page: number;
8
8
  pageSize: number;
9
9
  totalPages: number;
10
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<{
13
+ data: T[];
14
+ nextCursor: string | null;
15
+ }>;
11
16
  anyOtherRepository(args: any): Promise<void>;
12
17
  }
@@ -58,7 +58,7 @@ 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.getVerifyLocals = function (status, page, pageSize, filters) {
61
+ CustomRepository.prototype.getVerifyLocals2 = function (status, page, pageSize, filters) {
62
62
  return __awaiter(this, void 0, void 0, function () {
63
63
  var queryBuilder, globalValue, _a, data, total;
64
64
  return __generator(this, function (_b) {
@@ -129,6 +129,47 @@ var CustomRepository = /** @class */ (function (_super) {
129
129
  });
130
130
  });
131
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;
136
+ var _a;
137
+ return __generator(this, function (_b) {
138
+ switch (_b.label) {
139
+ case 0:
140
+ queryBuilder = this.createQueryBuilder('entity').take(limit + 1) // Fetch one more record than needed to determine if there's a next page
141
+ ;
142
+ if (status !== null && status >= 0) {
143
+ queryBuilder.andWhere('entity.status = :status', { status: status });
144
+ }
145
+ if (filters['global'] && filters['global'].value) {
146
+ globalValue = "%".concat(filters['global'].value, "%");
147
+ queryBuilder.andWhere('(JSON_EXTRACT(entity.local_information, "$.name") LIKE :globalValue ' +
148
+ 'OR JSON_EXTRACT(entity.local_information, "$.square.address") LIKE :globalValue ' +
149
+ 'OR JSON_EXTRACT(entity.local_information, "$.address.formatted_address") LIKE :globalValue ' +
150
+ 'OR entity.status LIKE :globalValue)', { globalValue: globalValue });
151
+ }
152
+ if (cursor) {
153
+ decodedCursor = Buffer.from(cursor, 'base64').toString('ascii');
154
+ queryBuilder.andWhere('entity.created > :cursor', {
155
+ cursor: decodedCursor,
156
+ });
157
+ }
158
+ queryBuilder.orderBy('entity.created', 'ASC');
159
+ return [4 /*yield*/, queryBuilder.getMany()];
160
+ case 1:
161
+ results = _b.sent();
162
+ nextCursor = results.length > limit ? (_a = results.pop()) === null || _a === void 0 ? void 0 : _a.created : null;
163
+ return [2 /*return*/, {
164
+ data: results,
165
+ nextCursor: nextCursor
166
+ ? Buffer.from(nextCursor.toISOString()).toString('base64')
167
+ : null,
168
+ }];
169
+ }
170
+ });
171
+ });
172
+ };
132
173
  CustomRepository.prototype.anyOtherRepository = function (args) {
133
174
  return __awaiter(this, void 0, void 0, function () {
134
175
  return __generator(this, function (_a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
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,7 +5,7 @@ export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
5
5
  super(target, dataSource.manager)
6
6
  }
7
7
 
8
- async getVerifyLocals(
8
+ async getVerifyLocals2(
9
9
  status: number | null,
10
10
  page: number,
11
11
  pageSize: number,
@@ -100,6 +100,50 @@ export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
100
100
  }
101
101
  }
102
102
 
103
+ async getVerifyLocals(
104
+ status: number | null,
105
+ cursor: string | null, // The cursor, typically an encoded value like an ID or timestamp
106
+ limit: number,
107
+ filters: any
108
+ ): Promise<{ data: T[]; nextCursor: string | null }> {
109
+ const queryBuilder = this.createQueryBuilder('entity').take(limit + 1) // Fetch one more record than needed to determine if there's a next page
110
+
111
+ if (status !== null && status >= 0) {
112
+ queryBuilder.andWhere('entity.status = :status', { status })
113
+ }
114
+
115
+ if (filters['global'] && filters['global'].value) {
116
+ const globalValue = `%${filters['global'].value}%`
117
+ queryBuilder.andWhere(
118
+ '(JSON_EXTRACT(entity.local_information, "$.name") LIKE :globalValue ' +
119
+ 'OR JSON_EXTRACT(entity.local_information, "$.square.address") LIKE :globalValue ' +
120
+ 'OR JSON_EXTRACT(entity.local_information, "$.address.formatted_address") LIKE :globalValue ' +
121
+ 'OR entity.status LIKE :globalValue)',
122
+ { globalValue }
123
+ )
124
+ }
125
+
126
+ if (cursor) {
127
+ // Decode and use the cursor for the WHERE clause
128
+ const decodedCursor = Buffer.from(cursor, 'base64').toString('ascii')
129
+ queryBuilder.andWhere('entity.created > :cursor', {
130
+ cursor: decodedCursor,
131
+ })
132
+ }
133
+
134
+ queryBuilder.orderBy('entity.created', 'ASC')
135
+
136
+ const results = await queryBuilder.getMany()
137
+ const nextCursor = results.length > limit ? results.pop()?.created : null
138
+
139
+ return {
140
+ data: results,
141
+ nextCursor: nextCursor
142
+ ? Buffer.from(nextCursor.toISOString()).toString('base64')
143
+ : null,
144
+ }
145
+ }
146
+
103
147
  async anyOtherRepository(args: any) {
104
148
  // Implementa otro método personalizado aquí
105
149
  }