@hichchi/nest-crud 0.0.6 → 0.0.8
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/CHANGELOG.md +16 -0
- package/README.md +679 -347
- package/base/base-entity.js +0 -1
- package/base/base-entity.js.map +1 -1
- package/base/base-repository.d.ts +3 -2
- package/base/base-repository.js +19 -8
- package/base/base-repository.js.map +1 -1
- package/base/base-user.entity.d.ts +59 -12
- package/base/base-user.entity.js +73 -15
- package/base/base-user.entity.js.map +1 -1
- package/crud.module.js +3 -3
- package/crud.module.js.map +1 -1
- package/decorators/entity.decorator.js +1 -1
- package/decorators/entity.decorator.js.map +1 -1
- package/decorators/page.decorator.d.ts +50 -2
- package/decorators/page.decorator.js +15 -3
- package/decorators/page.decorator.js.map +1 -1
- package/interfaces/crud-options.interfaces.d.ts +11 -3
- package/package.json +4 -4
- package/readme-top.md +5 -1
- package/responses/crud.error.responses.d.ts +22 -0
- package/responses/crud.error.responses.js +28 -0
- package/responses/crud.error.responses.js.map +1 -1
- package/services/crud.service.d.ts +61 -51
- package/services/crud.service.js +49 -41
- package/services/crud.service.js.map +1 -1
- package/types/find-conditions.type.d.ts +1 -1
|
@@ -95,6 +95,28 @@ declare const CrudErrorResponses: {
|
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
97
97
|
E_400_QUERY: (entityName: string, field?: string, description?: string) => ErrorResponse;
|
|
98
|
+
/**
|
|
99
|
+
* Error response for empty required field values
|
|
100
|
+
*
|
|
101
|
+
* This error occurs when a required field is provided as empty during
|
|
102
|
+
* request validation. It's commonly used in create and update operations
|
|
103
|
+
* where specific fields must contain a non-empty value.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} entityName - The name of the entity (e.g., 'user', 'product')
|
|
106
|
+
* @param {string} [field] - The name of the field that must not be empty
|
|
107
|
+
* @param {string} [description] - Optional additional context or details
|
|
108
|
+
* @returns {ErrorResponse} A formatted error response object
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* if (!dto.name?.trim()) {
|
|
113
|
+
* throw new BadRequestException(
|
|
114
|
+
* CrudErrorResponses.E_400_EMPTY('user', 'name')
|
|
115
|
+
* );
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
E_400_EMPTY: (entityName: string, field: string, description?: string) => ErrorResponse;
|
|
98
120
|
/**
|
|
99
121
|
* Error response for entity not found by ID
|
|
100
122
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// noinspection JSUnusedGlobalSymbols
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.CrudErrorResponses = void 0;
|
|
4
5
|
const utils_1 = require("@hichchi/utils");
|
|
@@ -113,6 +114,33 @@ const CrudErrorResponses = {
|
|
|
113
114
|
message: `Cannot find ${field ? `field with name '${field}'` : "a field provided as a filter or search"} in ${(0, utils_1.toLowerCaseBreak)(entityName)}!`,
|
|
114
115
|
description,
|
|
115
116
|
}),
|
|
117
|
+
/**
|
|
118
|
+
* Error response for empty required field values
|
|
119
|
+
*
|
|
120
|
+
* This error occurs when a required field is provided as empty during
|
|
121
|
+
* request validation. It's commonly used in create and update operations
|
|
122
|
+
* where specific fields must contain a non-empty value.
|
|
123
|
+
*
|
|
124
|
+
* @param {string} entityName - The name of the entity (e.g., 'user', 'product')
|
|
125
|
+
* @param {string} [field] - The name of the field that must not be empty
|
|
126
|
+
* @param {string} [description] - Optional additional context or details
|
|
127
|
+
* @returns {ErrorResponse} A formatted error response object
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* if (!dto.name?.trim()) {
|
|
132
|
+
* throw new BadRequestException(
|
|
133
|
+
* CrudErrorResponses.E_400_EMPTY('user', 'name')
|
|
134
|
+
* );
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
E_400_EMPTY: (entityName, field, description) => ({
|
|
139
|
+
statusCode: nest_connector_1.HttpClientErrorStatus.BAD_REQUEST,
|
|
140
|
+
code: `${(0, utils_1.toSnakeCase)(entityName, true)}_${nest_connector_1.HttpClientErrorStatus.BAD_REQUEST}_EMPTY_${(0, utils_1.toSnakeCase)(field, true)}`,
|
|
141
|
+
message: `${(0, utils_1.toFirstCaseBreak)(entityName)} ${(0, utils_1.toLowerCaseBreak)(field)} should not be empty!`,
|
|
142
|
+
description,
|
|
143
|
+
}),
|
|
116
144
|
/**
|
|
117
145
|
* Error response for entity not found by ID
|
|
118
146
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud.error.responses.js","sourceRoot":"","sources":["../../../../libs/nest-crud/src/responses/crud.error.responses.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crud.error.responses.js","sourceRoot":"","sources":["../../../../libs/nest-crud/src/responses/crud.error.responses.ts"],"names":[],"mappings":";AAAA,qCAAqC;;;AAErC,0CAAiG;AAEjG,4DAIiC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,kBAAkB,GAAG;IACvB;;;;;;;;;;;;;;;;;;OAkBG;IACH,gBAAgB,EAAE,CAAC,UAAkB,EAAE,KAAa,EAAE,WAAoB,EAAiB,EAAE,CAAC,CAAC;QAC3F,UAAU,EAAE,sCAAW,CAAC,WAAW;QACnC,IAAI,EAAE,GAAG,IAAA,mBAAW,EAAC,UAAU,EAAE,IAAI,CAAC,IAAI,sCAAW,CAAC,WAAW,eAAe,IAAA,mBAAW,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE;QAC1G,OAAO,EAAE,wBAAwB,IAAA,wBAAgB,EAAC,UAAU,CAAC,IAAI,IAAA,wBAAgB,EAAC,KAAK,CAAC,GAAG;QAC3F,WAAW;KACd,CAAC;IAEF;;;;;;;;;;;;;;;;;;OAkBG;IACH,gBAAgB,EAAE,CAAC,UAAkB,EAAE,WAAoB,E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E,IAAI,CAAC,EAAE;QAC7G,OAAO,EAAE,GAAG,IAAA,sBAAc,EAAC,UAAU,CAAC,eAAe,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,wBAAgB,EAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB;QAC7H,WAAW;KACd,CAAC;IAEF;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,eAAe,EAAE,CAAC,UAAkB,EAAE,SAAoB,EAAE,WAAoB,EAAiB,EAAE,CAAC,CAAC;QACjG,UAAU,EAAE,sCAAW,CAAC,qBAAqB;QAC7C,IAAI,EAAE,GAAG,IAAA,mBAAW,EAAC,UAAU,EAAE,IAAI,CAAC,IAAI,sCAAW,CAAC,qBAAqB,IAAI,IAAA,mBAAW,EAAC,SAAS,EAAE,IAAI,CAAC,EAAE;QAC7G,OAAO,EAAE,mCAAmC,IAAA,wBAAgB,EAAC,SAAS,CAAC,IAAI,IAAA,wBAAgB,EAAC,UAAU,CAAC,GAAG;QAC1G,WAAW;KACd,CAAC;IAEF;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,EAAE,CAAC,WAAoB,EAAiB,EAAE,CAAC,CAAC;QAC7C,UAAU,EAAE,sCAAW,CAAC,qBAAqB;QAC7C,IAAI,EAAE,KAAK,sCAAW,CAAC,qBAAqB,QAAQ;QACpD,OAAO,EAAE,4BAA4B;QACrC,WAAW;KACd,CAAC;CACL,CAAC;AAEO,gDAAkB"}
|
|
@@ -4,6 +4,7 @@ import { TypeORMErrorHandler } from "../types";
|
|
|
4
4
|
import { PaginatedResponse } from "@hichchi/nest-core";
|
|
5
5
|
import { SuccessResponse } from "@hichchi/nest-connector";
|
|
6
6
|
import { EntityDeepPartial, EntityId, Model, ModelExtension, Pagination, QueryDeepPartial, WithId } from "@hichchi/nest-connector/crud";
|
|
7
|
+
import { EntityManager } from "typeorm";
|
|
7
8
|
/**
|
|
8
9
|
* Abstract base service providing CRUD operations for entities
|
|
9
10
|
*
|
|
@@ -23,7 +24,7 @@ import { EntityDeepPartial, EntityId, Model, ModelExtension, Pagination, QueryDe
|
|
|
23
24
|
* The service is designed to work with repositories that extend BaseRepository,
|
|
24
25
|
* providing a consistent and type-safe way to interact with the database.
|
|
25
26
|
*
|
|
26
|
-
* @template
|
|
27
|
+
* @template Entity - The entity type this service manages. This type parameter
|
|
27
28
|
* represents the entity class that the service will work with.
|
|
28
29
|
* It must extend the Model interface.
|
|
29
30
|
*
|
|
@@ -76,12 +77,12 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
76
77
|
* The name of the entity this service manages
|
|
77
78
|
* @private
|
|
78
79
|
*/
|
|
79
|
-
|
|
80
|
+
protected readonly entityName: string;
|
|
80
81
|
/**
|
|
81
82
|
* Array of field names with unique constraints for the entity
|
|
82
83
|
* @private
|
|
83
84
|
*/
|
|
84
|
-
|
|
85
|
+
protected readonly uniqueFieldNames?: string[];
|
|
85
86
|
/**
|
|
86
87
|
* Creates a new instance of CrudService
|
|
87
88
|
*
|
|
@@ -90,7 +91,7 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
90
91
|
* includes the entity name and unique field names, which are used for error
|
|
91
92
|
* handling and response generation.
|
|
92
93
|
*
|
|
93
|
-
* @param {BaseRepository<
|
|
94
|
+
* @param {BaseRepository<Entity>} repository - The repository for the entity
|
|
94
95
|
* @throws {ImplementationException} If no repository is provided
|
|
95
96
|
*
|
|
96
97
|
* @example
|
|
@@ -147,9 +148,10 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
147
148
|
* provided values. Use the `save` method to persist the entity.
|
|
148
149
|
*
|
|
149
150
|
* @template T - Type that extends DeepPartial of the base entity
|
|
151
|
+
* @template Entity - Type of the entity
|
|
150
152
|
* @param {T} createDto - The data transfer object containing entity properties
|
|
151
153
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
152
|
-
* @returns {
|
|
154
|
+
* @returns {Entity} A new entity instance with the provided properties
|
|
153
155
|
* @throws {HttpException} If an error occurs during entity creation
|
|
154
156
|
*
|
|
155
157
|
* @example
|
|
@@ -172,11 +174,12 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
172
174
|
* After saving, it retrieves the entity with any specified relations or options.
|
|
173
175
|
*
|
|
174
176
|
* @template T - Type that extends DeepPartial of the base entity
|
|
177
|
+
* @template Entity - Type of the entity
|
|
175
178
|
* @param {T} createDto - The data transfer object containing entity properties
|
|
176
|
-
* @param {GetByIdOptions<
|
|
177
|
-
* @param {
|
|
179
|
+
* @param {GetByIdOptions<Entity>} [options] - Options for saving and retrieving the entity
|
|
180
|
+
* @param {WithId} [createdBy] - The user who created the entity (for audit tracking)
|
|
178
181
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
179
|
-
* @returns {Promise<
|
|
182
|
+
* @returns {Promise<Entity | null>} The saved entity or null if not found
|
|
180
183
|
* @throws {HttpException} If an error occurs during entity creation or saving
|
|
181
184
|
*
|
|
182
185
|
* @example
|
|
@@ -212,11 +215,12 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
212
215
|
* property on each entity if a user is provided.
|
|
213
216
|
*
|
|
214
217
|
* @template T - Type that extends DeepPartial of the base entity
|
|
218
|
+
* @template Entity - Type of the entity
|
|
215
219
|
* @param {T[]} createDtos - Array of data transfer objects containing entity properties
|
|
216
220
|
* @param {SaveOptionsWithSkip} [options] - Options for saving entities, including skipCreate flag to control whether new entities should be created during save operations. When skipCreate is true, only updates existing entities. Defaults to false.
|
|
217
|
-
* @param {
|
|
221
|
+
* @param {WithId} [createdBy] - The user who created the entities (for audit tracking)
|
|
218
222
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
219
|
-
* @returns {Promise<
|
|
223
|
+
* @returns {Promise<Entity[]>} Array of saved entities
|
|
220
224
|
* @throws {HttpException} If an error occurs during entity creation or saving
|
|
221
225
|
*
|
|
222
226
|
* @example
|
|
@@ -244,16 +248,17 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
244
248
|
* Updates an entity by its ID
|
|
245
249
|
*
|
|
246
250
|
* This method updates an entity with the specified ID using the provided data.
|
|
247
|
-
* It also sets the
|
|
251
|
+
* It also sets the createdBy property if a user is provided. After updating,
|
|
248
252
|
* it retrieves the updated entity with any specified relations or options.
|
|
249
253
|
*
|
|
250
254
|
* @template T - Type that extends QueryDeepPartial of the base entity
|
|
255
|
+
* @template Entity - Type of the entity
|
|
251
256
|
* @param {EntityId} id - The ID of the entity to update
|
|
252
257
|
* @param {T} updateDto - The data transfer object containing properties to update
|
|
253
|
-
* @param {GetByIdOptions<
|
|
254
|
-
* @param {
|
|
258
|
+
* @param {GetByIdOptions<Entity>} [options] - Options for retrieving the updated entity
|
|
259
|
+
* @param {WithId} [updatedBy] - The user who updated the entity (for audit tracking)
|
|
255
260
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
256
|
-
* @returns {Promise<
|
|
261
|
+
* @returns {Promise<Entity>} The updated entity
|
|
257
262
|
* @throws {NotFoundException} If the entity with the given ID is not found or ID is invalid
|
|
258
263
|
* @throws {InternalServerErrorException} If the update operation fails
|
|
259
264
|
* @throws {HttpException} If any other error occurs during the update
|
|
@@ -291,16 +296,17 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
291
296
|
* Updates a single entity that matches the specified conditions
|
|
292
297
|
*
|
|
293
298
|
* This method updates the first entity that matches the given conditions.
|
|
294
|
-
* It also sets the
|
|
299
|
+
* It also sets the createdBy property if a user is provided. After updating,
|
|
295
300
|
* it retrieves the updated entity.
|
|
296
301
|
*
|
|
297
302
|
* @template T - Type that extends QueryDeepPartial of the base entity
|
|
298
|
-
* @
|
|
303
|
+
* @template Entity - Type of the entity
|
|
304
|
+
* @param {QueryDeepPartial<Entity>} where - Conditions to find the entity to update
|
|
299
305
|
* @param {T} updateDto - The data transfer object containing properties to update
|
|
300
|
-
* @param {Omit<GetOneOptions<
|
|
301
|
-
* @param {
|
|
306
|
+
* @param {Omit<GetOneOptions<Entity>, "where">} options - Options for retrieving the updated entity, excluding the where condition
|
|
307
|
+
* @param {WithId} [updatedBy] - The user who updated the entity (for audit tracking)
|
|
302
308
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
303
|
-
* @returns {Promise<
|
|
309
|
+
* @returns {Promise<Entity>} The updated entity
|
|
304
310
|
* @throws {InternalServerErrorException} If the update operation fails
|
|
305
311
|
* @throws {HttpException} If any other error occurs during the update
|
|
306
312
|
*
|
|
@@ -325,18 +331,19 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
325
331
|
* @see {@link updateMany} Method to update multiple entities by conditions
|
|
326
332
|
* @see {@link BaseRepository.updateOne} Repository method that performs the actual update operation
|
|
327
333
|
*/
|
|
328
|
-
updateOne<T extends EntityDeepPartial<Entity>>(where: QueryDeepPartial<Entity
|
|
334
|
+
updateOne<T extends EntityDeepPartial<Entity>>(where: QueryDeepPartial<Entity> | QueryDeepPartial<Entity>[], updateDto: T, options?: Omit<GetOneOptions<Entity>, "where">, updatedBy?: WithId, eh?: TypeORMErrorHandler): Promise<Entity>;
|
|
329
335
|
/**
|
|
330
336
|
* Updates multiple entities that match the specified conditions
|
|
331
337
|
*
|
|
332
338
|
* This method updates all entities that match the given conditions.
|
|
333
|
-
* It also sets the
|
|
339
|
+
* It also sets the createdBy property if a user is provided. Unlike update and updateOne,
|
|
334
340
|
* this method returns a success response rather than the updated entities.
|
|
335
341
|
*
|
|
336
342
|
* @template T - Type that extends QueryDeepPartial of the base entity
|
|
337
|
-
* @
|
|
343
|
+
* @template Entity - Type of the entity
|
|
344
|
+
* @param {QueryDeepPartial<Entity>} where - Conditions to find entities to update
|
|
338
345
|
* @param {T} updateDto - The data transfer object containing properties to update
|
|
339
|
-
* @param {
|
|
346
|
+
* @param {WithId} [updatedBy] - The user who updated the entities (for audit tracking)
|
|
340
347
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
341
348
|
* @returns {Promise<SuccessResponse>} A success response indicating the update was successful
|
|
342
349
|
* @throws {InternalServerErrorException} If the update operation fails
|
|
@@ -365,18 +372,18 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
365
372
|
* @see {@link BaseRepository.updateMany} Repository method that performs the actual update operation
|
|
366
373
|
* @see {@link EntityUtils.handleSuccess} Utility method that generates the success response
|
|
367
374
|
*/
|
|
368
|
-
updateMany<T extends EntityDeepPartial<Entity>>(where: QueryDeepPartial<Entity
|
|
375
|
+
updateMany<T extends EntityDeepPartial<Entity>>(where: QueryDeepPartial<Entity> | QueryDeepPartial<Entity>[], updateDto: T, updatedBy?: WithId, eh?: TypeORMErrorHandler): Promise<SuccessResponse>;
|
|
369
376
|
/**
|
|
370
377
|
* Updates multiple entities by their IDs
|
|
371
378
|
*
|
|
372
379
|
* This method updates all entities with the specified IDs using the provided data.
|
|
373
|
-
* It also sets the
|
|
380
|
+
* It also sets the createdBy property if a user is provided. Like updateMany,
|
|
374
381
|
* this method returns a success response rather than the updated entities.
|
|
375
382
|
*
|
|
376
383
|
* @template T - Type that extends QueryDeepPartial of the base entity
|
|
377
384
|
* @param {EntityId[]} ids - Array of entity IDs to update
|
|
378
385
|
* @param {T} updateDto - The data transfer object containing properties to update
|
|
379
|
-
* @param {
|
|
386
|
+
* @param {WithId} [updatedBy] - The user who updated the entities (for audit tracking)
|
|
380
387
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
381
388
|
* @returns {Promise<SuccessResponse>} A success response indicating the update was successful
|
|
382
389
|
* @throws {NotFoundException} If any of the IDs are invalid
|
|
@@ -414,9 +421,9 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
414
421
|
* entities if specified in the options.
|
|
415
422
|
*
|
|
416
423
|
* @param {EntityId} id - The ID of the entity to retrieve
|
|
417
|
-
* @param {GetByIdOptions<
|
|
424
|
+
* @param {GetByIdOptions<Entity>} [options] - Options for retrieving the entity, such as relations to load
|
|
418
425
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
419
|
-
* @returns {Promise<
|
|
426
|
+
* @returns {Promise<Entity>} The retrieved entity
|
|
420
427
|
* @throws {NotFoundException} If the entity with the given ID is not found or ID is invalid
|
|
421
428
|
* @throws {HttpException} If any other error occurs during retrieval
|
|
422
429
|
*
|
|
@@ -443,9 +450,9 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
443
450
|
* This method fetches all entities with the specified IDs. It can also load related
|
|
444
451
|
* entities if specified in the options.
|
|
445
452
|
*
|
|
446
|
-
* @param {GetByIdsOptions<
|
|
453
|
+
* @param {GetByIdsOptions<Entity>} getByIds - Options for retrieving entities, including the IDs and relations
|
|
447
454
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
448
|
-
* @returns {Promise<
|
|
455
|
+
* @returns {Promise<Entity[]>} Array of retrieved entities
|
|
449
456
|
* @throws {NotFoundException} If any of the IDs are invalid
|
|
450
457
|
* @throws {HttpException} If any other error occurs during retrieval
|
|
451
458
|
*
|
|
@@ -476,9 +483,9 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
476
483
|
* This method fetches the first entity that matches the given conditions.
|
|
477
484
|
* It can also load related entities if specified in the options.
|
|
478
485
|
*
|
|
479
|
-
* @param {GetOneOptions<
|
|
486
|
+
* @param {GetOneOptions<Entity>} getOne - Options for retrieving the entity, including conditions and relations
|
|
480
487
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
481
|
-
* @returns {Promise<
|
|
488
|
+
* @returns {Promise<Entity>} The retrieved entity
|
|
482
489
|
* @throws {NotFoundException} If no entity matches the conditions
|
|
483
490
|
* @throws {HttpException} If any other error occurs during retrieval
|
|
484
491
|
*
|
|
@@ -510,9 +517,10 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
510
517
|
* information. Otherwise, it returns an array of entities.
|
|
511
518
|
*
|
|
512
519
|
* @template Options - Type that extends GetManyOptions for the base entity
|
|
520
|
+
* @template Entity - Type of the entity
|
|
513
521
|
* @param {Options} getMany - Options for retrieving entities, including conditions, relations, and pagination
|
|
514
522
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
515
|
-
* @returns {Promise<PaginatedResponse<
|
|
523
|
+
* @returns {Promise<PaginatedResponse<Entity> | Entity[]>} Paginated response or array of entities
|
|
516
524
|
* @throws {HttpException} If any error occurs during retrieval
|
|
517
525
|
*
|
|
518
526
|
* @example
|
|
@@ -554,9 +562,10 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
554
562
|
* of entities.
|
|
555
563
|
*
|
|
556
564
|
* @template Options - Type that extends GetAllOptions for the base entity
|
|
565
|
+
* @template Entity - Type of the entity
|
|
557
566
|
* @param {Options} [getAll] - Optional settings for retrieving entities, including relations and pagination
|
|
558
567
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
559
|
-
* @returns {Promise<PaginatedResponse<
|
|
568
|
+
* @returns {Promise<PaginatedResponse<Entity> | Entity[]>} Paginated response or array of entities
|
|
560
569
|
* @throws {HttpException} If any error occurs during retrieval
|
|
561
570
|
*
|
|
562
571
|
* @example
|
|
@@ -592,7 +601,7 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
592
601
|
* @param {EntityId} id - The ID of the entity to delete
|
|
593
602
|
* @param {true} wipe - When true, performs a hard delete (permanent removal)
|
|
594
603
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
595
|
-
* @returns {Promise<
|
|
604
|
+
* @returns {Promise<Entity>} The deleted entity
|
|
596
605
|
* @throws {NotFoundException} If the entity with the given ID is not found or ID is invalid
|
|
597
606
|
* @throws {HttpException} If any other error occurs during deletion
|
|
598
607
|
*/
|
|
@@ -603,9 +612,9 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
603
612
|
* This overload performs a soft delete and sets the deletedBy property for audit tracking.
|
|
604
613
|
*
|
|
605
614
|
* @param {EntityId} id - The ID of the entity to delete
|
|
606
|
-
* @param {
|
|
615
|
+
* @param {WithId} deletedBy - The user who deleted the entity (for audit tracking)
|
|
607
616
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
608
|
-
* @returns {Promise<
|
|
617
|
+
* @returns {Promise<Entity>} The deleted entity
|
|
609
618
|
* @throws {NotFoundException} If the entity with the given ID is not found or ID is invalid
|
|
610
619
|
* @throws {HttpException} If any other error occurs during deletion
|
|
611
620
|
*/
|
|
@@ -615,10 +624,10 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
615
624
|
*
|
|
616
625
|
* This method supports both soft delete (default) and hard delete (permanent removal).
|
|
617
626
|
*
|
|
618
|
-
* @param {QueryDeepPartial<
|
|
627
|
+
* @param {QueryDeepPartial<Entity>} where - Conditions to find the entity to delete
|
|
619
628
|
* @param {true} wipe - When true, performs a hard delete (permanent removal)
|
|
620
629
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
621
|
-
* @returns {Promise<
|
|
630
|
+
* @returns {Promise<Entity>} The deleted entity
|
|
622
631
|
* @throws {NotFoundException} If no entity matches the conditions
|
|
623
632
|
* @throws {HttpException} If any other error occurs during deletion
|
|
624
633
|
*/
|
|
@@ -628,10 +637,10 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
628
637
|
*
|
|
629
638
|
* This overload performs a soft delete and sets the deletedBy property for audit tracking.
|
|
630
639
|
*
|
|
631
|
-
* @param {QueryDeepPartial<
|
|
632
|
-
* @param {
|
|
640
|
+
* @param {QueryDeepPartial<Entity>} where - Conditions to find the entity to delete
|
|
641
|
+
* @param {WithId} deletedBy - The user who deleted the entity (for audit tracking)
|
|
633
642
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
634
|
-
* @returns {Promise<
|
|
643
|
+
* @returns {Promise<Entity>} The deleted entity
|
|
635
644
|
* @throws {NotFoundException} If no entity matches the conditions
|
|
636
645
|
* @throws {HttpException} If any other error occurs during deletion
|
|
637
646
|
*/
|
|
@@ -641,10 +650,10 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
641
650
|
*
|
|
642
651
|
* This method supports both soft delete (default) and hard delete (permanent removal).
|
|
643
652
|
*
|
|
644
|
-
* @param {QueryDeepPartial<
|
|
653
|
+
* @param {QueryDeepPartial<Entity>} where - Conditions to find entities to delete
|
|
645
654
|
* @param {true} wipe - When true, performs a hard delete (permanent removal)
|
|
646
655
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
647
|
-
* @returns {Promise<
|
|
656
|
+
* @returns {Promise<Entity[]>} Array of deleted entities
|
|
648
657
|
* @throws {NotFoundException} If no entities match the conditions
|
|
649
658
|
* @throws {HttpException} If any other error occurs during deletion
|
|
650
659
|
*/
|
|
@@ -654,10 +663,10 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
654
663
|
*
|
|
655
664
|
* This overload performs a soft delete and sets the deletedBy property for audit tracking.
|
|
656
665
|
*
|
|
657
|
-
* @param {QueryDeepPartial<
|
|
658
|
-
* @param {
|
|
666
|
+
* @param {QueryDeepPartial<Entity>} where - Conditions to find entities to delete
|
|
667
|
+
* @param {WithId} deletedBy - The user who deleted the entities (for audit tracking)
|
|
659
668
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
660
|
-
* @returns {Promise<
|
|
669
|
+
* @returns {Promise<Entity[]>} Array of deleted entities
|
|
661
670
|
* @throws {NotFoundException} If no entities match the conditions
|
|
662
671
|
* @throws {HttpException} If any other error occurs during deletion
|
|
663
672
|
*/
|
|
@@ -683,7 +692,7 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
683
692
|
* This overload performs a soft delete and sets the deletedBy property for audit tracking.
|
|
684
693
|
*
|
|
685
694
|
* @param {EntityId[]} ids - Array of entity IDs to delete
|
|
686
|
-
* @param {
|
|
695
|
+
* @param {WithId} deletedBy - The user who deleted the entities (for audit tracking)
|
|
687
696
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
688
697
|
* @returns {Promise<SuccessResponse>} A success response indicating the deletion was successful
|
|
689
698
|
* @throws {NotFoundException} If no entities with the given IDs are found
|
|
@@ -696,7 +705,7 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
696
705
|
* This method returns the number of entities that match the given conditions.
|
|
697
706
|
* It's useful for getting counts without retrieving the actual entities.
|
|
698
707
|
*
|
|
699
|
-
* @param {GetManyOptions<
|
|
708
|
+
* @param {GetManyOptions<Entity>} [getMany] - Options for filtering entities to count
|
|
700
709
|
* @param {TypeORMErrorHandler} [eh] - Optional custom error handler
|
|
701
710
|
* @returns {Promise<number>} The number of entities that match the conditions
|
|
702
711
|
* @throws {HttpException} If any error occurs during the count operation
|
|
@@ -732,13 +741,14 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
732
741
|
* If an error occurs, the transaction is rolled back.
|
|
733
742
|
*
|
|
734
743
|
* @template T - The return type of the operation
|
|
744
|
+
* @param {(manager: EntityManager) => Promise<T>} operation - The operation to execute within the transaction
|
|
735
745
|
* @returns {Promise<T>} The result of the operation
|
|
736
746
|
* @throws {HttpException} If any error occurs during the transaction
|
|
737
747
|
*
|
|
738
748
|
* @example
|
|
739
749
|
* ```typescript
|
|
740
750
|
* // Execute multiple operations in a transaction
|
|
741
|
-
* const result = await userService.transaction(async (manager) => {
|
|
751
|
+
* const result = await userService.transaction(async (manager: EntityManager) => {
|
|
742
752
|
* // Create a user
|
|
743
753
|
* const user = await manager.getRepository(UserEntity).save({
|
|
744
754
|
* name: 'John Doe',
|
|
@@ -757,7 +767,7 @@ export declare abstract class CrudService<Entity extends Model | ModelExtension>
|
|
|
757
767
|
*
|
|
758
768
|
* @see {@link BaseRepository.transaction} Repository method that manages the transaction
|
|
759
769
|
*/
|
|
760
|
-
transaction<T>(operation: () => Promise<T>): Promise<T>;
|
|
770
|
+
transaction<T>(operation: (manager: EntityManager) => Promise<T>): Promise<T>;
|
|
761
771
|
/**
|
|
762
772
|
* Executes a function with error handling
|
|
763
773
|
*
|