test-entity-library-asm 2.3.1 → 2.3.3
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.
- package/dist/CustomRepository.d.ts +2 -5
- package/dist/CustomRepository.js +21 -50
- package/package.json +1 -1
- package/src/CustomRepository.ts +18 -69
|
@@ -1,12 +1,9 @@
|
|
|
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,
|
|
4
|
+
getVerifyLocals(status: number | null, cursor: string | null, limit: number, filters: any): Promise<{
|
|
5
5
|
data: T[];
|
|
6
|
-
|
|
7
|
-
page: number;
|
|
8
|
-
pageSize: number;
|
|
9
|
-
totalPages: number;
|
|
6
|
+
nextCursor: string | null;
|
|
10
7
|
}>;
|
|
11
8
|
anyOtherRepository(args: any): Promise<void>;
|
|
12
9
|
}
|
package/dist/CustomRepository.js
CHANGED
|
@@ -58,15 +58,15 @@ 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,
|
|
61
|
+
CustomRepository.prototype.getVerifyLocals = function (status, cursor, limit, filters) {
|
|
62
62
|
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
-
var queryBuilder, globalValue,
|
|
63
|
+
var queryBuilder, globalValue, decodedCursor, cursorDate, results, nextCursor;
|
|
64
|
+
var _a;
|
|
64
65
|
return __generator(this, function (_b) {
|
|
65
66
|
switch (_b.label) {
|
|
66
67
|
case 0:
|
|
67
|
-
queryBuilder = this.createQueryBuilder('entity')
|
|
68
|
-
|
|
69
|
-
.take(pageSize);
|
|
68
|
+
queryBuilder = this.createQueryBuilder('entity').take(limit + 1) // Fetch one more record than needed to determine if there's a next page
|
|
69
|
+
;
|
|
70
70
|
if (status !== null && status >= 0) {
|
|
71
71
|
queryBuilder.andWhere('entity.status = :status', { status: status });
|
|
72
72
|
}
|
|
@@ -77,53 +77,24 @@ var CustomRepository = /** @class */ (function (_super) {
|
|
|
77
77
|
'OR JSON_EXTRACT(entity.local_information, "$.address.formatted_address") LIKE :globalValue ' +
|
|
78
78
|
'OR entity.status LIKE :globalValue)', { globalValue: globalValue });
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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()];
|
|
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
|
+
});
|
|
87
|
+
}
|
|
88
|
+
queryBuilder.orderBy('entity.created', 'ASC');
|
|
89
|
+
return [4 /*yield*/, queryBuilder.getMany()];
|
|
119
90
|
case 1:
|
|
120
|
-
|
|
91
|
+
results = _b.sent();
|
|
92
|
+
nextCursor = results.length > limit ? (_a = results.pop()) === null || _a === void 0 ? void 0 : _a.created : null;
|
|
121
93
|
return [2 /*return*/, {
|
|
122
|
-
data:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
totalPages: Math.ceil(total / pageSize),
|
|
94
|
+
data: results,
|
|
95
|
+
nextCursor: nextCursor
|
|
96
|
+
? Buffer.from(nextCursor.toISOString()).toString('base64')
|
|
97
|
+
: null,
|
|
127
98
|
}];
|
|
128
99
|
}
|
|
129
100
|
});
|
package/package.json
CHANGED
package/src/CustomRepository.ts
CHANGED
|
@@ -7,13 +7,11 @@ export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
|
7
7
|
|
|
8
8
|
async getVerifyLocals(
|
|
9
9
|
status: number | null,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
cursor: string | null,
|
|
11
|
+
limit: number,
|
|
12
12
|
filters: any
|
|
13
|
-
) {
|
|
14
|
-
const queryBuilder = this.createQueryBuilder('entity')
|
|
15
|
-
.skip((page - 1) * pageSize)
|
|
16
|
-
.take(pageSize)
|
|
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
|
|
17
15
|
|
|
18
16
|
if (status !== null && status >= 0) {
|
|
19
17
|
queryBuilder.andWhere('entity.status = :status', { status })
|
|
@@ -30,73 +28,24 @@ export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
|
30
28
|
)
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
})
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
|
|
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
|
-
})
|
|
39
|
+
queryBuilder.orderBy('entity.created', 'ASC')
|
|
91
40
|
|
|
92
|
-
const
|
|
41
|
+
const results = await queryBuilder.getMany()
|
|
42
|
+
const nextCursor = results.length > limit ? results.pop()?.created : null
|
|
93
43
|
|
|
94
44
|
return {
|
|
95
|
-
data,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
totalPages: Math.ceil(total / pageSize),
|
|
45
|
+
data: results,
|
|
46
|
+
nextCursor: nextCursor
|
|
47
|
+
? Buffer.from(nextCursor.toISOString()).toString('base64')
|
|
48
|
+
: null,
|
|
100
49
|
}
|
|
101
50
|
}
|
|
102
51
|
|