xcally-nest-library 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "xcally-nest-library",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.8",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -62,6 +62,7 @@
|
|
62
62
|
"eslint-plugin-prettier": "^5.1.3",
|
63
63
|
"jest": "^29.7.0",
|
64
64
|
"prettier": "^3.2.5",
|
65
|
+
"rimraf": "^5.0.5",
|
65
66
|
"source-map-support": "^0.5.21",
|
66
67
|
"supertest": "^6.3.4",
|
67
68
|
"ts-jest": "^29.1.2",
|
@@ -48,13 +48,11 @@ export class GenericRepository<E extends ObjectLiteral> {
|
|
48
48
|
* @throws Error if the entity is not found.
|
49
49
|
*/
|
50
50
|
async update<T extends DeepPartial<E> & IId>(dto: T): Promise<E> {
|
51
|
-
const
|
52
|
-
|
53
|
-
} as unknown as FindOptionsWhere<E>);
|
54
|
-
if (!entity) {
|
51
|
+
const entityUpdated = await this.repository.update(dto.id, dto as any);
|
52
|
+
if (!entityUpdated.affected) {
|
55
53
|
throw new Error('Entity not found');
|
56
54
|
}
|
57
|
-
return this.repository.
|
55
|
+
return this.repository.findOneBy({ id: Equal(dto.id) } as unknown as FindOptionsWhere<E>);
|
58
56
|
}
|
59
57
|
|
60
58
|
/**
|
@@ -85,9 +83,20 @@ export class GenericRepository<E extends ObjectLiteral> {
|
|
85
83
|
return this.repository.count();
|
86
84
|
}
|
87
85
|
|
88
|
-
|
89
|
-
|
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
|
+
* @throws Error if the entity is not found.
|
92
|
+
*/
|
93
|
+
async findById(id: number): Promise<E> {
|
94
|
+
const entity = await this.repository.findOneBy({
|
90
95
|
id: Equal(id),
|
91
96
|
} as unknown as FindOptionsWhere<E>);
|
97
|
+
if (!entity) {
|
98
|
+
throw new Error('Entity not found');
|
99
|
+
}
|
100
|
+
return entity;
|
92
101
|
}
|
93
102
|
}
|