xcally-nest-library 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
package/index.ts CHANGED
@@ -4,7 +4,6 @@ export * from './src/interceptors/serialize.interceptor';
4
4
  export * from './src/modules/logger/winston.service';
5
5
  export * from './src/modules/logger/winston.module';
6
6
  export * from './src/modules/tracer/tracer.module';
7
- export * from './src/db/typeorm/generic.repository';
8
7
  export * from './src/decorators/utils.decorators';
9
8
  export * from './src/config/env.validation';
10
9
  export * from './src/modules/logger/pino/logger.service';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcally-nest-library",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -41,7 +41,6 @@
41
41
  "datadog-winston": "^1.6.0",
42
42
  "nest-winston": "^1.9.4",
43
43
  "nestjs-grpc-exceptions": "^0.2.2",
44
- "nestjs-paginate": "^8.6.2",
45
44
  "nestjs-pino": "^4.1.0",
46
45
  "pino": "^9.4.0",
47
46
  "pino-pretty": "^11.2.2",
@@ -1,110 +0,0 @@
1
- import { Repository, EntityTarget, EntityManager, Equal, FindOptionsWhere, ObjectLiteral, DeepPartial } from 'typeorm';
2
- import { PaginateConfig, PaginateQuery, Paginated, paginate } from 'nestjs-paginate';
3
-
4
- interface IId {
5
- id: number;
6
- }
7
-
8
- /**
9
- * Represents a generic repository for managing entities.
10
- */
11
- export class GenericRepository<E extends ObjectLiteral> {
12
- protected repository: Repository<E>;
13
- protected paginateConfig: PaginateConfig<E>;
14
-
15
- constructor(
16
- private readonly entityManager: EntityManager,
17
- entity: EntityTarget<E>,
18
- paginateConfig: PaginateConfig<E>,
19
- ) {
20
- this.repository = this.entityManager.getRepository(entity);
21
- this.paginateConfig = paginateConfig;
22
- }
23
- /**
24
- * Retrieves a paginated list of entities based on the provided query.
25
- *
26
- * @param query - The pagination query parameters.
27
- * @returns A promise that resolves to a paginated list of entities.
28
- */
29
- getMany(query: PaginateQuery): Promise<Paginated<E>> {
30
- return paginate(query, this.repository, this.paginateConfig);
31
- }
32
- /**
33
- * Saves an entity to the database.
34
- *
35
- * @param entity - The entity to be saved.
36
- * @returns A promise that resolves to the saved entity.
37
- */
38
- save<T extends DeepPartial<E>>(entity: T): Promise<E> {
39
- const res = this.repository.create({ ...entity });
40
- return this.repository.save(res);
41
- }
42
-
43
- /**
44
- * Updates an entity in the database.
45
- *
46
- * @param dto - The updated entity data.
47
- * @returns A promise that resolves to the updated entity.
48
- * @throws Error if the entity is not found.
49
- */
50
- async update<T extends DeepPartial<E> & IId>(dto: T): Promise<E> {
51
- const entityUpdated = await this.repository.update(dto.id, dto as any);
52
- if (!entityUpdated.affected) {
53
- return undefined;
54
- }
55
- return this.repository.findOneBy({ id: Equal(dto.id) } as unknown as FindOptionsWhere<E>);
56
- }
57
-
58
- /**
59
- * Counts the number of entities that match the provided options.
60
- *
61
- * @param options - The options to filter the entities.
62
- * @returns A promise that resolves to the number of entities that match the options.
63
- */
64
- count(options: FindOptionsWhere<E>): Promise<number> {
65
- return this.repository.count(options);
66
- }
67
-
68
- /**
69
- * Retrieves all entities from the database.
70
- *
71
- * @returns A promise that resolves to an array of entities.
72
- */
73
- findAll(): Promise<E[]> {
74
- return this.repository.find();
75
- }
76
-
77
- /**
78
- * Retrieves the total count of all entities in the database.
79
- *
80
- * @returns A promise that resolves to the total count of entities.
81
- */
82
- countAll(): Promise<number> {
83
- return this.repository.count();
84
- }
85
-
86
- /**
87
- * Retrieves an entity from the database based on its ID.
88
- *
89
- * @param id - The ID of the entity to retrieve.
90
- * @returns A promise that resolves to the retrieved entity.
91
- */
92
- async findById(id: number): Promise<E> {
93
- return await this.repository.findOneBy({
94
- id: Equal(id),
95
- } as unknown as FindOptionsWhere<E>);
96
- }
97
-
98
- /**
99
- * Removes an entity from the database based on its ID.
100
- *
101
- * @param id - The ID of the entity to remove.
102
- * @returns A promise that resolves when the entity is successfully removed.
103
- */
104
- async remove(id: number): Promise<void> {
105
- await this.repository.delete(id);
106
- }
107
- async remove2(id: number): Promise<void> {
108
- await this.repository.delete(id);
109
- }
110
- }