xcally-nest-library 0.0.1 → 0.0.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/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "xcally-nest-library",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.3",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -8,7 +8,7 @@
|
|
8
8
|
"license": "UNLICENSED",
|
9
9
|
"scripts": {
|
10
10
|
"prepublish": "pnpm build",
|
11
|
-
"build": "
|
11
|
+
"build": "tsc",
|
12
12
|
"build:watch": "rimraf dist && tsc-watch -b -v",
|
13
13
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
14
14
|
"prettier:check": "prettier --check ./**/*.{ts,js,json,*rc}",
|
@@ -39,6 +39,7 @@
|
|
39
39
|
"datadog-winston": "^1.6.0",
|
40
40
|
"nest-winston": "^1.9.4",
|
41
41
|
"nestjs-grpc-exceptions": "^0.2.2",
|
42
|
+
"nestjs-paginate": "^8.6.2",
|
42
43
|
"reflect-metadata": "^0.2.2",
|
43
44
|
"rxjs": "^7.8.1",
|
44
45
|
"typeorm": "^0.3.20",
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { Repository, EntityTarget, EntityManager, Equal, FindOptionsWhere, ObjectLiteral, DeepPartial } from 'typeorm';
|
2
2
|
import { Injectable } from '@nestjs/common';
|
3
|
+
import { PaginateConfig, PaginateQuery, Paginated, paginate } from 'nestjs-paginate';
|
3
4
|
|
4
5
|
interface IId {
|
5
6
|
id: number;
|
@@ -9,17 +10,23 @@ interface IGenericRepository<E> {
|
|
9
10
|
save<T extends DeepPartial<E>>(entity: T): Promise<E>;
|
10
11
|
update<T extends DeepPartial<E> & IId>(entity: T): Promise<E>;
|
11
12
|
count(options: FindOptionsWhere<E>): Promise<number>;
|
13
|
+
getMany(query: PaginateQuery): Promise<Paginated<E>>;
|
12
14
|
}
|
13
15
|
|
14
16
|
@Injectable()
|
15
17
|
export class GenericRepository<E extends ObjectLiteral> implements IGenericRepository<E> {
|
16
18
|
protected repository: Repository<E>;
|
17
|
-
|
19
|
+
protected paginateConfig: PaginateConfig<E>;
|
18
20
|
constructor(
|
19
21
|
readonly entityManager: EntityManager,
|
20
22
|
entity: EntityTarget<E>,
|
23
|
+
paginateConfig: PaginateConfig<E>,
|
21
24
|
) {
|
22
25
|
this.repository = entityManager.getRepository(entity);
|
26
|
+
this.paginateConfig = paginateConfig;
|
27
|
+
}
|
28
|
+
getMany(query: PaginateQuery): Promise<Paginated<E>> {
|
29
|
+
return paginate(query, this.repository, this.paginateConfig);
|
23
30
|
}
|
24
31
|
save<T extends DeepPartial<E>>(entity: T): Promise<E> {
|
25
32
|
const res = this.repository.create({ ...entity });
|