@mondart/nestjs-common-module 2.6.0 → 2.6.5
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/dist/lib/core-crud/controllers/core-crud.controller.js +10 -7
- package/dist/lib/core-crud/services/core-crud.service.d.ts +16 -16
- package/dist/lib/core-crud/services/core-crud.service.js +16 -16
- package/dist/lib/saga/exceptions/saga-invocation.exception.js +1 -1
- package/dist/lib/saga/index.d.ts +1 -0
- package/dist/lib/saga/index.js +3 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -11,39 +11,42 @@ class CoreCrudController {
|
|
|
11
11
|
CoreCrudController.responseDto = responseDto;
|
|
12
12
|
}
|
|
13
13
|
async findAllWithPagination(query, paginateConfig, options, ...args) {
|
|
14
|
-
const response = await this.coreService.findAllWithPagination(query, paginateConfig, options);
|
|
14
|
+
const response = await this.coreService.findAllWithPagination(query, paginateConfig, options, ...args);
|
|
15
15
|
if (!response)
|
|
16
16
|
throw new common_1.NotFoundException(enums_1.SharedMessages.FETCH_FAILED);
|
|
17
17
|
const serializedData = response.data.map((item) => new this.responseDto(item));
|
|
18
|
-
return new dto_1.SuccessResponse(serializedData, enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK, {
|
|
18
|
+
return new dto_1.SuccessResponse(serializedData, enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK, {
|
|
19
|
+
...response.meta,
|
|
20
|
+
links: response.links,
|
|
21
|
+
});
|
|
19
22
|
}
|
|
20
23
|
async findOneById(id, options, ...args) {
|
|
21
|
-
const response = await this.coreService.findOneById(id, options);
|
|
24
|
+
const response = await this.coreService.findOneById(id, options, ...args);
|
|
22
25
|
if (!response)
|
|
23
26
|
throw new common_1.NotFoundException(enums_1.SharedMessages.RESOURCE_NOT_FOUND);
|
|
24
27
|
return new dto_1.SuccessResponse(new this.responseDto(response), enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK);
|
|
25
28
|
}
|
|
26
29
|
async create(createDto, options, ...args) {
|
|
27
|
-
const response = await this.coreService.create(createDto, options);
|
|
30
|
+
const response = await this.coreService.create(createDto, options, ...args);
|
|
28
31
|
if (!response)
|
|
29
32
|
throw new common_1.BadRequestException(enums_1.SharedMessages.CREATE_FAILED);
|
|
30
33
|
return new dto_1.SuccessResponse(new this.responseDto(response), enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.CREATED);
|
|
31
34
|
}
|
|
32
35
|
async update({ id }, updateDto, options, ...args) {
|
|
33
|
-
const response = await this.coreService.update(id, updateDto, options);
|
|
36
|
+
const response = await this.coreService.update(id, updateDto, options, ...args);
|
|
34
37
|
if (!response)
|
|
35
38
|
throw new common_1.BadRequestException(enums_1.SharedMessages.UPDATE_FAILED);
|
|
36
39
|
const foundItem = await this.coreService.findOneById(id, options);
|
|
37
40
|
return new dto_1.SuccessResponse(new this.responseDto(foundItem), enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK);
|
|
38
41
|
}
|
|
39
42
|
async deleteById({ id }, options, ...args) {
|
|
40
|
-
const result = await this.coreService.deleteById(id, options);
|
|
43
|
+
const result = await this.coreService.deleteById(id, options, ...args);
|
|
41
44
|
if (!result)
|
|
42
45
|
throw new common_1.BadRequestException(enums_1.SharedMessages.DELETE_FAILED);
|
|
43
46
|
return new dto_1.SuccessResponse(undefined, enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK);
|
|
44
47
|
}
|
|
45
48
|
async softDeleteById({ id }, options, ...args) {
|
|
46
|
-
const result = await this.coreService.softDeleteById(id, options);
|
|
49
|
+
const result = await this.coreService.softDeleteById(id, options, ...args);
|
|
47
50
|
if (!result)
|
|
48
51
|
throw new common_1.BadRequestException(enums_1.SharedMessages.DELETE_FAILED);
|
|
49
52
|
return new dto_1.SuccessResponse(undefined, enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK);
|
|
@@ -11,22 +11,22 @@ export declare abstract class CoreCrudService<T extends BaseModelEntity, CreateD
|
|
|
11
11
|
protected readonly repository: Repository<T>;
|
|
12
12
|
private readonly relationsPath;
|
|
13
13
|
protected constructor(repository: Repository<T>);
|
|
14
|
-
create(createDto: CreateDto, options?: CoreBaseServiceOption): Promise<T>;
|
|
15
|
-
update(id: number, updateDto: Partial<UpdateDto> | DeepPartial<T> | QueryDeepPartialEntity<T>, options?: CoreUpdateServiceOption<T
|
|
16
|
-
updateMany(query: FindManyOptions<T>, updateDto: Partial<UpdateDto> | DeepPartial<T> | QueryDeepPartialEntity<T>, options?: CoreUpdateServiceOption<T
|
|
17
|
-
upsert(upsertDto: QueryDeepPartialEntity<T>, upsertOptions: UpsertOptions<T>, options?: CoreBaseServiceOption): Promise<InsertResult>;
|
|
18
|
-
findAllWithPagination(query: PaginationQueryCustom, paginateConfig: PaginateConfig<T>, options?: CoreFindAllWithPaginationServiceOption<T
|
|
19
|
-
findAll(query: FindManyOptions<T>, options?: CoreFindAllServiceOption): Promise<T[]>;
|
|
20
|
-
findOneById(id: number, options?: CoreFindOneByIdServiceOption<T
|
|
21
|
-
findOne(query: FindManyOptions<T>, options?: CoreFindOneServiceOption): Promise<T>;
|
|
22
|
-
isExists(query: FindManyOptions<T>, options?: CoreBaseServiceOption): Promise<boolean>;
|
|
23
|
-
count(query: FindManyOptions<T>, options?: CoreBaseServiceOption): Promise<number>;
|
|
24
|
-
softDelete(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption): Promise<UpdateResult>;
|
|
25
|
-
softDeleteById(id: string | string[] | number | number[], options?: CoreBaseServiceOption): Promise<UpdateResult>;
|
|
26
|
-
restore(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption): Promise<UpdateResult>;
|
|
27
|
-
restoreById(id: string | string[] | number | number[], options?: CoreBaseServiceOption): Promise<UpdateResult>;
|
|
28
|
-
delete(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption): Promise<DeleteResult>;
|
|
29
|
-
deleteById(id: string | string[] | number | number[], options?: CoreBaseServiceOption): Promise<DeleteResult>;
|
|
14
|
+
create(createDto: CreateDto, options?: CoreBaseServiceOption, ...args: any[]): Promise<T>;
|
|
15
|
+
update(id: number, updateDto: Partial<UpdateDto> | DeepPartial<T> | QueryDeepPartialEntity<T>, options?: CoreUpdateServiceOption<T>, ...args: any[]): Promise<UpdateResult>;
|
|
16
|
+
updateMany(query: FindManyOptions<T>, updateDto: Partial<UpdateDto> | DeepPartial<T> | QueryDeepPartialEntity<T>, options?: CoreUpdateServiceOption<T>, ...args: any[]): Promise<void>;
|
|
17
|
+
upsert(upsertDto: QueryDeepPartialEntity<T>, upsertOptions: UpsertOptions<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<InsertResult>;
|
|
18
|
+
findAllWithPagination(query: PaginationQueryCustom, paginateConfig: PaginateConfig<T>, options?: CoreFindAllWithPaginationServiceOption<T>, ...args: any[]): Promise<Paginated<T>>;
|
|
19
|
+
findAll(query: FindManyOptions<T>, options?: CoreFindAllServiceOption, ...args: any[]): Promise<T[]>;
|
|
20
|
+
findOneById(id: number, options?: CoreFindOneByIdServiceOption<T>, ...args: any[]): Promise<T>;
|
|
21
|
+
findOne(query: FindManyOptions<T>, options?: CoreFindOneServiceOption, ...args: any[]): Promise<T>;
|
|
22
|
+
isExists(query: FindManyOptions<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<boolean>;
|
|
23
|
+
count(query: FindManyOptions<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<number>;
|
|
24
|
+
softDelete(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<UpdateResult>;
|
|
25
|
+
softDeleteById(id: string | string[] | number | number[], options?: CoreBaseServiceOption, ...args: any[]): Promise<UpdateResult>;
|
|
26
|
+
restore(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<UpdateResult>;
|
|
27
|
+
restoreById(id: string | string[] | number | number[], options?: CoreBaseServiceOption, ...args: any[]): Promise<UpdateResult>;
|
|
28
|
+
delete(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<DeleteResult>;
|
|
29
|
+
deleteById(id: string | string[] | number | number[], options?: CoreBaseServiceOption, ...args: any[]): Promise<DeleteResult>;
|
|
30
30
|
private relatedPropertyTransformer;
|
|
31
31
|
private whereQueryTransformer;
|
|
32
32
|
private isObject;
|
|
@@ -12,7 +12,7 @@ class CoreCrudService {
|
|
|
12
12
|
const metadata = this.repository.metadata;
|
|
13
13
|
this.relationsPath = metadata.relations.map((relation) => relation.propertyPath);
|
|
14
14
|
}
|
|
15
|
-
async create(createDto, options) {
|
|
15
|
+
async create(createDto, options, ...args) {
|
|
16
16
|
createDto = this.relatedPropertyTransformer(createDto);
|
|
17
17
|
const entity = this.repository.create(createDto);
|
|
18
18
|
if (options?.entityManager) {
|
|
@@ -22,7 +22,7 @@ class CoreCrudService {
|
|
|
22
22
|
return await this.repository.save(entity);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
async update(id, updateDto, options) {
|
|
25
|
+
async update(id, updateDto, options, ...args) {
|
|
26
26
|
updateDto = this.relatedPropertyTransformer(updateDto);
|
|
27
27
|
if (!options?.entityManager) {
|
|
28
28
|
const selectFields = Object.keys(updateDto);
|
|
@@ -67,13 +67,13 @@ class CoreCrudService {
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
async updateMany(query, updateDto, options) {
|
|
70
|
+
async updateMany(query, updateDto, options, ...args) {
|
|
71
71
|
const foundEntities = await this.findAll(query, options);
|
|
72
72
|
for await (const entity of foundEntities) {
|
|
73
73
|
await this.update(entity.id, updateDto, options).catch((err) => console.log(err));
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
async upsert(upsertDto, upsertOptions, options) {
|
|
76
|
+
async upsert(upsertDto, upsertOptions, options, ...args) {
|
|
77
77
|
try {
|
|
78
78
|
upsertDto = this.relatedPropertyTransformer(upsertDto);
|
|
79
79
|
let conflictPaths = [];
|
|
@@ -110,7 +110,7 @@ class CoreCrudService {
|
|
|
110
110
|
throw new common_1.BadRequestException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.UPSERT_FAILED, error));
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
async findAllWithPagination(query, paginateConfig, options) {
|
|
113
|
+
async findAllWithPagination(query, paginateConfig, options, ...args) {
|
|
114
114
|
return await (0, nestjs_paginate_1.paginate)(query, options?.selectQueryBuilder
|
|
115
115
|
? options.selectQueryBuilder
|
|
116
116
|
: this.repository, {
|
|
@@ -122,7 +122,7 @@ class CoreCrudService {
|
|
|
122
122
|
: undefined,
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
|
-
async findAll(query, options) {
|
|
125
|
+
async findAll(query, options, ...args) {
|
|
126
126
|
let result;
|
|
127
127
|
query.where = this.whereQueryTransformer(query.where) ?? undefined;
|
|
128
128
|
if (!options?.entityManager)
|
|
@@ -144,7 +144,7 @@ class CoreCrudService {
|
|
|
144
144
|
}
|
|
145
145
|
return result;
|
|
146
146
|
}
|
|
147
|
-
async findOneById(id, options) {
|
|
147
|
+
async findOneById(id, options, ...args) {
|
|
148
148
|
let result;
|
|
149
149
|
if (options?.entityManager) {
|
|
150
150
|
result = await options.entityManager.findOne(this.repository.target, {
|
|
@@ -175,7 +175,7 @@ class CoreCrudService {
|
|
|
175
175
|
}
|
|
176
176
|
return result;
|
|
177
177
|
}
|
|
178
|
-
async findOne(query, options) {
|
|
178
|
+
async findOne(query, options, ...args) {
|
|
179
179
|
let result;
|
|
180
180
|
query.where = this.whereQueryTransformer(query.where) ?? undefined;
|
|
181
181
|
if (options?.entityManager) {
|
|
@@ -199,7 +199,7 @@ class CoreCrudService {
|
|
|
199
199
|
}
|
|
200
200
|
return result;
|
|
201
201
|
}
|
|
202
|
-
async isExists(query, options) {
|
|
202
|
+
async isExists(query, options, ...args) {
|
|
203
203
|
let result;
|
|
204
204
|
query.where = this.whereQueryTransformer(query.where) ?? undefined;
|
|
205
205
|
if (options?.entityManager) {
|
|
@@ -210,7 +210,7 @@ class CoreCrudService {
|
|
|
210
210
|
}
|
|
211
211
|
return result;
|
|
212
212
|
}
|
|
213
|
-
async count(query, options) {
|
|
213
|
+
async count(query, options, ...args) {
|
|
214
214
|
let result;
|
|
215
215
|
query.where = this.whereQueryTransformer(query.where) ?? undefined;
|
|
216
216
|
if (options?.entityManager) {
|
|
@@ -221,7 +221,7 @@ class CoreCrudService {
|
|
|
221
221
|
}
|
|
222
222
|
return result;
|
|
223
223
|
}
|
|
224
|
-
async softDelete(query, options) {
|
|
224
|
+
async softDelete(query, options, ...args) {
|
|
225
225
|
const formatedQuery = this.whereQueryTransformer(query) ?? undefined;
|
|
226
226
|
if (options?.entityManager) {
|
|
227
227
|
return await options?.entityManager.softDelete(this.repository.target, formatedQuery);
|
|
@@ -230,7 +230,7 @@ class CoreCrudService {
|
|
|
230
230
|
return await this.repository.softDelete(formatedQuery);
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
-
async softDeleteById(id, options) {
|
|
233
|
+
async softDeleteById(id, options, ...args) {
|
|
234
234
|
if (options?.entityManager) {
|
|
235
235
|
return await options?.entityManager.softDelete(this.repository.target, id);
|
|
236
236
|
}
|
|
@@ -238,7 +238,7 @@ class CoreCrudService {
|
|
|
238
238
|
return await this.repository.softDelete(id);
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
async restore(query, options) {
|
|
241
|
+
async restore(query, options, ...args) {
|
|
242
242
|
const formatedQuery = this.whereQueryTransformer(query) ?? undefined;
|
|
243
243
|
if (options?.entityManager) {
|
|
244
244
|
return await options?.entityManager.restore(this.repository.target, formatedQuery);
|
|
@@ -247,7 +247,7 @@ class CoreCrudService {
|
|
|
247
247
|
return await this.repository.restore(formatedQuery);
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
|
-
async restoreById(id, options) {
|
|
250
|
+
async restoreById(id, options, ...args) {
|
|
251
251
|
if (options?.entityManager) {
|
|
252
252
|
return await options?.entityManager.restore(this.repository.target, id);
|
|
253
253
|
}
|
|
@@ -255,7 +255,7 @@ class CoreCrudService {
|
|
|
255
255
|
return await this.repository.restore(id);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
|
-
async delete(query, options) {
|
|
258
|
+
async delete(query, options, ...args) {
|
|
259
259
|
const formatedQuery = this.whereQueryTransformer(query) ?? undefined;
|
|
260
260
|
if (options?.entityManager) {
|
|
261
261
|
return await options?.entityManager.delete(this.repository.target, formatedQuery);
|
|
@@ -264,7 +264,7 @@ class CoreCrudService {
|
|
|
264
264
|
return await this.repository.delete(formatedQuery);
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
|
-
async deleteById(id, options) {
|
|
267
|
+
async deleteById(id, options, ...args) {
|
|
268
268
|
if (options?.entityManager) {
|
|
269
269
|
return await options?.entityManager.delete(this.repository.target, id);
|
|
270
270
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SagaInvocationException = void 0;
|
|
4
4
|
class SagaInvocationException extends Error {
|
|
5
5
|
constructor(originalError, step) {
|
|
6
|
-
super(originalError.message);
|
|
6
|
+
super(`${step}: ${originalError.message}`);
|
|
7
7
|
this.originalError = originalError;
|
|
8
8
|
this.step = step;
|
|
9
9
|
Object.setPrototypeOf(this, SagaInvocationException.prototype);
|
package/dist/lib/saga/index.d.ts
CHANGED
package/dist/lib/saga/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Saga = exports.SagaModule = exports.SagaBuilder = exports.SagaStatus = exports.SagaInvocationException = exports.SagaCompensationException = void 0;
|
|
3
|
+
exports.SagaStep = exports.Saga = exports.SagaModule = exports.SagaBuilder = exports.SagaStatus = exports.SagaInvocationException = exports.SagaCompensationException = void 0;
|
|
4
4
|
var exceptions_1 = require("./exceptions");
|
|
5
5
|
Object.defineProperty(exports, "SagaCompensationException", { enumerable: true, get: function () { return exceptions_1.SagaCompensationException; } });
|
|
6
6
|
Object.defineProperty(exports, "SagaInvocationException", { enumerable: true, get: function () { return exceptions_1.SagaInvocationException; } });
|
|
@@ -12,3 +12,5 @@ var saga_module_1 = require("./saga.module");
|
|
|
12
12
|
Object.defineProperty(exports, "SagaModule", { enumerable: true, get: function () { return saga_module_1.SagaModule; } });
|
|
13
13
|
var decorators_1 = require("./decorators");
|
|
14
14
|
Object.defineProperty(exports, "Saga", { enumerable: true, get: function () { return decorators_1.Saga; } });
|
|
15
|
+
var types_1 = require("./types");
|
|
16
|
+
Object.defineProperty(exports, "SagaStep", { enumerable: true, get: function () { return types_1.SagaStep; } });
|