nestjs-paginate 5.1.0 → 6.0.0
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/README.md +3 -17
- package/lib/__tests__/cat.entity.d.ts +6 -0
- package/lib/__tests__/cat.entity.js +14 -1
- package/lib/__tests__/cat.entity.js.map +1 -1
- package/lib/paginate.d.ts +0 -6
- package/lib/paginate.js +3 -21
- package/lib/paginate.js.map +1 -1
- package/lib/paginate.spec.js +82 -18
- package/lib/paginate.spec.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -254,20 +254,6 @@ const paginateConfig: PaginateConfig<CatEntity> {
|
|
|
254
254
|
*/
|
|
255
255
|
origin: 'http://cats.example',
|
|
256
256
|
|
|
257
|
-
/**
|
|
258
|
-
* Required: false
|
|
259
|
-
* Type: string
|
|
260
|
-
* Description: Allow user to choose between limit/offset and take/skip.
|
|
261
|
-
* Default: PaginationType.TAKE_AND_SKIP
|
|
262
|
-
*
|
|
263
|
-
* However, using limit/offset can return unexpected results.
|
|
264
|
-
* For more information see:
|
|
265
|
-
* [#477](https://github.com/ppetzold/nestjs-paginate/issues/477)
|
|
266
|
-
* [#4742](https://github.com/typeorm/typeorm/issues/4742)
|
|
267
|
-
* [#5670](https://github.com/typeorm/typeorm/issues/5670)
|
|
268
|
-
*/
|
|
269
|
-
paginationType: PaginationType.LIMIT_AND_OFFSET,
|
|
270
|
-
|
|
271
257
|
/**
|
|
272
258
|
* Required: false
|
|
273
259
|
* Type: boolean
|
|
@@ -406,9 +392,9 @@ Filter operators must be whitelisted per column in `PaginateConfig`.
|
|
|
406
392
|
|
|
407
393
|
`?filter.createdAt=$btw:2022-02-02,2022-02-10` where column `createdAt` is between the dates `2022-02-02` and `2022-02-10`
|
|
408
394
|
|
|
409
|
-
`?filter.roles=$contains:
|
|
395
|
+
`?filter.roles=$contains:moderator` where column `roles` is an array and contains the value `moderator`
|
|
410
396
|
|
|
411
|
-
`?filter.roles=$contains:
|
|
397
|
+
`?filter.roles=$contains:moderator,admin` where column `roles` is an array and contains the values `moderator` and `admin`
|
|
412
398
|
|
|
413
399
|
## Multi Filters
|
|
414
400
|
|
|
@@ -418,7 +404,7 @@ Multi filters are filters that can be applied to a single column with a comparat
|
|
|
418
404
|
|
|
419
405
|
`?filter.id=$gt:3&filter.id=$lt:5` where column `id` is greater than `3` **and** less than `5`
|
|
420
406
|
|
|
421
|
-
`?filter.id=$
|
|
407
|
+
`?filter.id=$contains:moderator&filter.id=$or:$contains:admin` where column `roles` is an array and contains `moderator` **or** `admin`
|
|
422
408
|
|
|
423
409
|
`?filter.id=$gt:3&filter.id=$and:$lt:5&filter.id=$or:$eq:7` where column `id` is greater than `3` **and** less than `5` **or** equal to `7`
|
|
424
410
|
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { CatToyEntity } from './cat-toy.entity';
|
|
2
2
|
import { CatHomeEntity } from './cat-home.entity';
|
|
3
3
|
import { SizeEmbed } from './size.embed';
|
|
4
|
+
export declare enum CutenessLevel {
|
|
5
|
+
LOW = "low",
|
|
6
|
+
MEDIUM = "medium",
|
|
7
|
+
HIGH = "high"
|
|
8
|
+
}
|
|
4
9
|
export declare class CatEntity {
|
|
5
10
|
id: number;
|
|
6
11
|
name: string;
|
|
7
12
|
color: string;
|
|
8
13
|
age: number | null;
|
|
14
|
+
cutenessLevel: CutenessLevel;
|
|
9
15
|
size: SizeEmbed;
|
|
10
16
|
toys: CatToyEntity[];
|
|
11
17
|
home: CatHomeEntity;
|
|
@@ -10,11 +10,17 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
var CatEntity_1;
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.CatEntity = void 0;
|
|
13
|
+
exports.CatEntity = exports.CutenessLevel = void 0;
|
|
14
14
|
const typeorm_1 = require("typeorm");
|
|
15
15
|
const cat_toy_entity_1 = require("./cat-toy.entity");
|
|
16
16
|
const cat_home_entity_1 = require("./cat-home.entity");
|
|
17
17
|
const size_embed_1 = require("./size.embed");
|
|
18
|
+
var CutenessLevel;
|
|
19
|
+
(function (CutenessLevel) {
|
|
20
|
+
CutenessLevel["LOW"] = "low";
|
|
21
|
+
CutenessLevel["MEDIUM"] = "medium";
|
|
22
|
+
CutenessLevel["HIGH"] = "high";
|
|
23
|
+
})(CutenessLevel = exports.CutenessLevel || (exports.CutenessLevel = {}));
|
|
18
24
|
let CatEntity = CatEntity_1 = class CatEntity {
|
|
19
25
|
afterLoad() {
|
|
20
26
|
var _a;
|
|
@@ -39,6 +45,13 @@ __decorate([
|
|
|
39
45
|
(0, typeorm_1.Column)({ nullable: true }),
|
|
40
46
|
__metadata("design:type", Number)
|
|
41
47
|
], CatEntity.prototype, "age", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, typeorm_1.Column)({
|
|
50
|
+
type: 'simple-enum',
|
|
51
|
+
enum: CutenessLevel,
|
|
52
|
+
}),
|
|
53
|
+
__metadata("design:type", String)
|
|
54
|
+
], CatEntity.prototype, "cutenessLevel", void 0);
|
|
42
55
|
__decorate([
|
|
43
56
|
(0, typeorm_1.Column)(() => size_embed_1.SizeEmbed),
|
|
44
57
|
__metadata("design:type", size_embed_1.SizeEmbed)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cat.entity.js","sourceRoot":"","sources":["../../src/__tests__/cat.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,qCAYgB;AAChB,qDAA+C;AAC/C,uDAAiD;AACjD,6CAAwC;
|
|
1
|
+
{"version":3,"file":"cat.entity.js","sourceRoot":"","sources":["../../src/__tests__/cat.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,qCAYgB;AAChB,qDAA+C;AAC/C,uDAAiD;AACjD,6CAAwC;AAExC,IAAY,aAIX;AAJD,WAAY,aAAa;IACrB,4BAAW,CAAA;IACX,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CAAC;IAC3B,IAAA,mBAAS,GAAE;;0CACQ;AAEpB;IAAC,IAAA,mBAAS,GAAE;IACZ,yDAAyD;IACzD,mGAAmG;;;;;0CAKlG;AAhDQ,SAAS;IADrB,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;GACX,SAAS,CAiDrB;AAjDY,8BAAS"}
|
package/lib/paginate.d.ts
CHANGED
|
@@ -25,10 +25,6 @@ export declare class Paginated<T> {
|
|
|
25
25
|
last?: string;
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
export declare enum PaginationType {
|
|
29
|
-
LIMIT_AND_OFFSET = "limit",
|
|
30
|
-
TAKE_AND_SKIP = "take"
|
|
31
|
-
}
|
|
32
28
|
export interface PaginateConfig<T> {
|
|
33
29
|
relations?: FindOptionsRelations<T> | RelationColumn<T>[];
|
|
34
30
|
sortableColumns: Column<T>[];
|
|
@@ -46,10 +42,8 @@ export interface PaginateConfig<T> {
|
|
|
46
42
|
withDeleted?: boolean;
|
|
47
43
|
relativePath?: boolean;
|
|
48
44
|
origin?: string;
|
|
49
|
-
paginationType?: PaginationType;
|
|
50
45
|
}
|
|
51
46
|
export declare const DEFAULT_MAX_LIMIT = 100;
|
|
52
47
|
export declare const DEFAULT_LIMIT = 20;
|
|
53
48
|
export declare const NO_PAGINATION = 0;
|
|
54
|
-
export declare const DEFAULT_PAGINATE_TYPE = PaginationType.TAKE_AND_SKIP;
|
|
55
49
|
export declare function paginate<T extends ObjectLiteral>(query: PaginateQuery, repo: Repository<T> | SelectQueryBuilder<T>, config: PaginateConfig<T>): Promise<Paginated<T>>;
|
package/lib/paginate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.paginate = exports.
|
|
3
|
+
exports.paginate = exports.NO_PAGINATION = exports.DEFAULT_LIMIT = exports.DEFAULT_MAX_LIMIT = exports.Paginated = exports.FilterSuffix = exports.FilterOperator = void 0;
|
|
4
4
|
const typeorm_1 = require("typeorm");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const lodash_1 = require("lodash");
|
|
@@ -13,21 +13,14 @@ const logger = new common_1.Logger('nestjs-paginate');
|
|
|
13
13
|
class Paginated {
|
|
14
14
|
}
|
|
15
15
|
exports.Paginated = Paginated;
|
|
16
|
-
var PaginationType;
|
|
17
|
-
(function (PaginationType) {
|
|
18
|
-
PaginationType["LIMIT_AND_OFFSET"] = "limit";
|
|
19
|
-
PaginationType["TAKE_AND_SKIP"] = "take";
|
|
20
|
-
})(PaginationType = exports.PaginationType || (exports.PaginationType = {}));
|
|
21
16
|
exports.DEFAULT_MAX_LIMIT = 100;
|
|
22
17
|
exports.DEFAULT_LIMIT = 20;
|
|
23
18
|
exports.NO_PAGINATION = 0;
|
|
24
|
-
exports.DEFAULT_PAGINATE_TYPE = PaginationType.TAKE_AND_SKIP;
|
|
25
19
|
async function paginate(query, repo, config) {
|
|
26
20
|
const page = (0, helper_1.positiveNumberOrDefault)(query.page, 1, 1);
|
|
27
21
|
const defaultLimit = config.defaultLimit || exports.DEFAULT_LIMIT;
|
|
28
22
|
const maxLimit = (0, helper_1.positiveNumberOrDefault)(config.maxLimit, exports.DEFAULT_MAX_LIMIT);
|
|
29
23
|
const queryLimit = (0, helper_1.positiveNumberOrDefault)(query.limit, defaultLimit);
|
|
30
|
-
const paginationType = config.paginationType || exports.DEFAULT_PAGINATE_TYPE;
|
|
31
24
|
const isPaginated = !(queryLimit === exports.NO_PAGINATION && maxLimit === exports.NO_PAGINATION);
|
|
32
25
|
const limit = isPaginated ? Math.min(queryLimit || defaultLimit, maxLimit || exports.DEFAULT_MAX_LIMIT) : exports.NO_PAGINATION;
|
|
33
26
|
const sortBy = [];
|
|
@@ -75,18 +68,7 @@ async function paginate(query, repo, config) {
|
|
|
75
68
|
}
|
|
76
69
|
}
|
|
77
70
|
if (isPaginated) {
|
|
78
|
-
|
|
79
|
-
// However, using limit/offset can return unexpected results.
|
|
80
|
-
// For more information see:
|
|
81
|
-
// [#477](https://github.com/ppetzold/nestjs-paginate/issues/477)
|
|
82
|
-
// [#4742](https://github.com/typeorm/typeorm/issues/4742)
|
|
83
|
-
// [#5670](https://github.com/typeorm/typeorm/issues/5670)
|
|
84
|
-
if (paginationType === PaginationType.LIMIT_AND_OFFSET) {
|
|
85
|
-
queryBuilder.limit(limit).offset((page - 1) * limit);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
queryBuilder.take(limit).skip((page - 1) * limit);
|
|
89
|
-
}
|
|
71
|
+
queryBuilder.limit(limit).offset((page - 1) * limit);
|
|
90
72
|
}
|
|
91
73
|
if (config.relations) {
|
|
92
74
|
// relations: ["relation"]
|
|
@@ -172,7 +154,7 @@ async function paginate(query, repo, config) {
|
|
|
172
154
|
parameters: [alias, `:${property.column}`],
|
|
173
155
|
};
|
|
174
156
|
if (['postgres', 'cockroachdb'].includes(queryBuilder.connection.options.type)) {
|
|
175
|
-
condition.parameters[0]
|
|
157
|
+
condition.parameters[0] = `CAST(${condition.parameters[0]} AS text)`;
|
|
176
158
|
}
|
|
177
159
|
qb.orWhere(qb['createWhereConditionExpression'](condition), {
|
|
178
160
|
[property.column]: `%${query.search}%`,
|
package/lib/paginate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.js","sourceRoot":"","sources":["../src/paginate.ts"],"names":[],"mappings":";;;AAAA,qCAQgB;AAEhB,2CAAoE;AACpE,mCAAgC;AAChC,6CAAuC;AAEvC,qCAciB;AACjB,qCAAkE;AAIzD,+FAJW,uBAAc,OAIX;AAAE,6FAJW,qBAAY,OAIX;AAFrC,MAAM,MAAM,GAAW,IAAI,eAAM,CAAC,iBAAiB,CAAC,CAAA;AAIpD,MAAa,SAAS;CAmBrB;AAnBD,8BAmBC;
|
|
1
|
+
{"version":3,"file":"paginate.js","sourceRoot":"","sources":["../src/paginate.ts"],"names":[],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AC,CAAC,SAAS,CAAC,CAAC,CAAC;YAC3C,QAAQ,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;YACxD,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC;YACxB,IAAI,EAAE,IAAI,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;YAC7D,IAAI,EAAE,IAAI,IAAI,UAAU,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC;SAC9E;KACJ,CAAA;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,SAAS,EAAK,EAAE,OAAO,CAAC,CAAA;AACrD,CAAC;AAjPD,4BAiPC"}
|
package/lib/paginate.spec.js
CHANGED
|
@@ -20,24 +20,60 @@ describe('paginate', () => {
|
|
|
20
20
|
let catHomes;
|
|
21
21
|
let catHomePillows;
|
|
22
22
|
beforeAll(async () => {
|
|
23
|
-
dataSource = new typeorm_1.DataSource({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
dataSource = new typeorm_1.DataSource(Object.assign(Object.assign({}, (process.env.DB === 'postgres'
|
|
24
|
+
? {
|
|
25
|
+
type: 'postgres',
|
|
26
|
+
host: 'localhost',
|
|
27
|
+
port: 5432,
|
|
28
|
+
username: 'root',
|
|
29
|
+
password: 'pass',
|
|
30
|
+
database: 'test',
|
|
31
|
+
}
|
|
32
|
+
: {
|
|
33
|
+
type: 'sqlite',
|
|
34
|
+
database: ':memory:',
|
|
35
|
+
})), { synchronize: true, logging: false, entities: [cat_entity_1.CatEntity, cat_toy_entity_1.CatToyEntity, cat_home_entity_1.CatHomeEntity, cat_home_pillow_entity_1.CatHomePillowEntity] }));
|
|
30
36
|
await dataSource.initialize();
|
|
31
37
|
catRepo = dataSource.getRepository(cat_entity_1.CatEntity);
|
|
32
38
|
catToyRepo = dataSource.getRepository(cat_toy_entity_1.CatToyEntity);
|
|
33
39
|
catHomeRepo = dataSource.getRepository(cat_home_entity_1.CatHomeEntity);
|
|
34
40
|
catHomePillowRepo = dataSource.getRepository(cat_home_pillow_entity_1.CatHomePillowEntity);
|
|
35
41
|
cats = await catRepo.save([
|
|
36
|
-
catRepo.create({
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
catRepo.create({
|
|
43
|
+
name: 'Milo',
|
|
44
|
+
color: 'brown',
|
|
45
|
+
age: 6,
|
|
46
|
+
cutenessLevel: cat_entity_1.CutenessLevel.HIGH,
|
|
47
|
+
size: { height: 25, width: 10, length: 40 },
|
|
48
|
+
}),
|
|
49
|
+
catRepo.create({
|
|
50
|
+
name: 'Garfield',
|
|
51
|
+
color: 'ginger',
|
|
52
|
+
age: 5,
|
|
53
|
+
cutenessLevel: cat_entity_1.CutenessLevel.MEDIUM,
|
|
54
|
+
size: { height: 30, width: 15, length: 45 },
|
|
55
|
+
}),
|
|
56
|
+
catRepo.create({
|
|
57
|
+
name: 'Shadow',
|
|
58
|
+
color: 'black',
|
|
59
|
+
age: 4,
|
|
60
|
+
cutenessLevel: cat_entity_1.CutenessLevel.HIGH,
|
|
61
|
+
size: { height: 25, width: 10, length: 50 },
|
|
62
|
+
}),
|
|
63
|
+
catRepo.create({
|
|
64
|
+
name: 'George',
|
|
65
|
+
color: 'white',
|
|
66
|
+
age: 3,
|
|
67
|
+
cutenessLevel: cat_entity_1.CutenessLevel.LOW,
|
|
68
|
+
size: { height: 35, width: 12, length: 40 },
|
|
69
|
+
}),
|
|
70
|
+
catRepo.create({
|
|
71
|
+
name: 'Leche',
|
|
72
|
+
color: 'white',
|
|
73
|
+
age: null,
|
|
74
|
+
cutenessLevel: cat_entity_1.CutenessLevel.HIGH,
|
|
75
|
+
size: { height: 10, width: 5, length: 15 },
|
|
76
|
+
}),
|
|
41
77
|
]);
|
|
42
78
|
catToys = await catToyRepo.save([
|
|
43
79
|
catToyRepo.create({ name: 'Fuzzy Thing', cat: cats[0], size: { height: 10, width: 10, length: 10 } }),
|
|
@@ -58,8 +94,32 @@ describe('paginate', () => {
|
|
|
58
94
|
catHomePillowRepo.create({ color: 'teal', home: catHomes[1] }),
|
|
59
95
|
]);
|
|
60
96
|
// add friends to Milo
|
|
61
|
-
catRepo.save(Object.assign(Object.assign({}, cats[0]), { friends: cats.slice(1) }));
|
|
62
|
-
});
|
|
97
|
+
await catRepo.save(Object.assign(Object.assign({}, cats[0]), { friends: cats.slice(1) }));
|
|
98
|
+
});
|
|
99
|
+
// TODO: Make all tests pass postgres driver.
|
|
100
|
+
if (process.env.DB === 'postgres') {
|
|
101
|
+
it('should return result based on search term including a camelcase named column', async () => {
|
|
102
|
+
const config = {
|
|
103
|
+
sortableColumns: ['id', 'name', 'color'],
|
|
104
|
+
searchableColumns: ['cutenessLevel'],
|
|
105
|
+
};
|
|
106
|
+
const query = {
|
|
107
|
+
path: '',
|
|
108
|
+
search: 'hi',
|
|
109
|
+
};
|
|
110
|
+
const result = await (0, paginate_1.paginate)(query, catRepo, config);
|
|
111
|
+
expect(result.meta.search).toStrictEqual('hi');
|
|
112
|
+
expect(result.data).toStrictEqual([cats[0], cats[2], cats[4]]);
|
|
113
|
+
expect(result.links.current).toBe('?page=1&limit=20&sortBy=id:ASC&search=hi');
|
|
114
|
+
});
|
|
115
|
+
afterAll(async () => {
|
|
116
|
+
const entities = dataSource.entityMetadatas;
|
|
117
|
+
const tableNames = entities.map((entity) => `"${entity.tableName}"`).join(', ');
|
|
118
|
+
await dataSource.query(`TRUNCATE ${tableNames} CASCADE;`);
|
|
119
|
+
});
|
|
120
|
+
// We end postgres coverage here. See TODO above.
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
63
123
|
it('should return an instance of Paginated', async () => {
|
|
64
124
|
const config = {
|
|
65
125
|
sortableColumns: ['id'],
|
|
@@ -391,9 +451,9 @@ describe('paginate', () => {
|
|
|
391
451
|
};
|
|
392
452
|
const result = await (0, paginate_1.paginate)(query, catRepo, config);
|
|
393
453
|
expect(result.meta.search).toStrictEqual('Mouse');
|
|
394
|
-
const toy = (0, lodash_1.clone)(catToys[
|
|
454
|
+
const toy = (0, lodash_1.clone)(catToys[1]);
|
|
395
455
|
delete toy.cat;
|
|
396
|
-
const toy2 = (0, lodash_1.clone)(catToys[
|
|
456
|
+
const toy2 = (0, lodash_1.clone)(catToys[2]);
|
|
397
457
|
delete toy2.cat;
|
|
398
458
|
expect(result.data).toStrictEqual([Object.assign((0, lodash_1.clone)(cats[0]), { toys: [toy2, toy] })]);
|
|
399
459
|
expect(result.links.current).toBe('?page=1&limit=20&sortBy=id:ASC&search=Mouse');
|
|
@@ -723,7 +783,7 @@ describe('paginate', () => {
|
|
|
723
783
|
delete copy.cat;
|
|
724
784
|
return copy;
|
|
725
785
|
});
|
|
726
|
-
copyCats[0].toys = [copyToys[0], copyToys[
|
|
786
|
+
copyCats[0].toys = [copyToys[0], copyToys[2], copyToys[1]];
|
|
727
787
|
copyCats[1].toys = [copyToys[3]];
|
|
728
788
|
const orderedCats = [copyCats[3], copyCats[1], copyCats[2], copyCats[0], copyCats[4]];
|
|
729
789
|
expect(result.data).toStrictEqual(orderedCats);
|
|
@@ -1604,6 +1664,7 @@ describe('paginate', () => {
|
|
|
1604
1664
|
await catRepo.softDelete({ id: cats[0].id });
|
|
1605
1665
|
const result = await (0, paginate_1.paginate)(query, catRepo, config);
|
|
1606
1666
|
expect(result.meta.totalItems).toBe(cats.length);
|
|
1667
|
+
await catRepo.restore({ id: cats[0].id });
|
|
1607
1668
|
});
|
|
1608
1669
|
it('should return only undeleted items', async () => {
|
|
1609
1670
|
const config = {
|
|
@@ -1616,6 +1677,7 @@ describe('paginate', () => {
|
|
|
1616
1677
|
await catRepo.softDelete({ id: cats[0].id });
|
|
1617
1678
|
const result = await (0, paginate_1.paginate)(query, catRepo, config);
|
|
1618
1679
|
expect(result.meta.totalItems).toBe(cats.length - 1);
|
|
1680
|
+
await catRepo.restore({ id: cats[0].id });
|
|
1619
1681
|
});
|
|
1620
1682
|
it('should return the specified columns only', async () => {
|
|
1621
1683
|
const config = {
|
|
@@ -1687,7 +1749,9 @@ describe('paginate', () => {
|
|
|
1687
1749
|
path: '',
|
|
1688
1750
|
};
|
|
1689
1751
|
const result = await (0, paginate_1.paginate)(query, catRepo, config);
|
|
1690
|
-
expect(result.
|
|
1752
|
+
expect(result.meta.totalItems).toBe(5);
|
|
1753
|
+
expect(result.data.length).toBe(5);
|
|
1754
|
+
expect(result.data[0].friends.length).toBe(4);
|
|
1691
1755
|
});
|
|
1692
1756
|
it('should return eager relations when set the property `loadEagerRelations` as true', async () => {
|
|
1693
1757
|
const config = {
|