xcally-nest-library 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,6 @@
1
1
  {
2
- "editor.codeActionsOnSave": { "source.fixAll": true },
2
+ "editor.codeActionsOnSave": {
3
+ "source.fixAll": "explicit"
4
+ },
3
5
  "editor.formatOnSave": false
4
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcally-nest-library",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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 });