@mondart/nestjs-common-module 1.1.53 → 1.1.55
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/controllers/core-crud.controller.d.ts +2 -2
- package/dist/controllers/core-crud.controller.js +2 -2
- package/dist/helpers/index.d.ts +2 -1
- package/dist/helpers/index.js +2 -1
- package/dist/helpers/rxjs-catch-error.helper.d.ts +1 -0
- package/dist/helpers/{kafka-catch-error.helper.js → rxjs-catch-error.helper.js} +5 -4
- package/dist/helpers/rxjs-timeout-custom-callback.helper.d.ts +2 -0
- package/dist/helpers/rxjs-timeout-custom-callback.helper.js +15 -0
- package/dist/services/core-crud.service.js +7 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/helpers/kafka-catch-error.helper.d.ts +0 -1
|
@@ -13,6 +13,6 @@ export declare class CoreCrudController<T extends BaseModelEntity, CreateDto, Up
|
|
|
13
13
|
findOneById(id: number): Promise<SuccessResponse<ResponseDto>>;
|
|
14
14
|
create(createDto: CreateDto): Promise<SuccessResponse<ResponseDto>>;
|
|
15
15
|
update({ id }: IdDto, updateDto: UpdateDto): Promise<SuccessResponse<ResponseDto>>;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
deleteById({ id }: IdDto): Promise<SuccessResponse<void>>;
|
|
17
|
+
softDeleteById({ id }: IdDto): Promise<SuccessResponse<void>>;
|
|
18
18
|
}
|
|
@@ -49,13 +49,13 @@ class CoreCrudController {
|
|
|
49
49
|
const foundItem = await this.coreService.findOneById(id);
|
|
50
50
|
return new dto_1.SuccessResponse(new this.responseDto(foundItem), enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK);
|
|
51
51
|
}
|
|
52
|
-
async
|
|
52
|
+
async deleteById({ id }) {
|
|
53
53
|
const result = await this.coreService.deleteById(id);
|
|
54
54
|
if (!result)
|
|
55
55
|
throw new common_1.BadRequestException(enums_1.SharedMessages.DELETE_FAILED);
|
|
56
56
|
return new dto_1.SuccessResponse(undefined, enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK);
|
|
57
57
|
}
|
|
58
|
-
async
|
|
58
|
+
async softDeleteById({ id }) {
|
|
59
59
|
const result = await this.coreService.softDeleteById(id);
|
|
60
60
|
if (!result)
|
|
61
61
|
throw new common_1.BadRequestException(enums_1.SharedMessages.DELETE_FAILED);
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export * from './get-env.helper';
|
|
|
2
2
|
export * from './multi-inheritance.helper';
|
|
3
3
|
export * from './message-formatter.helper';
|
|
4
4
|
export * from './convert-string-case.helper';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './rxjs-catch-error.helper';
|
|
6
|
+
export * from './rxjs-timeout-custom-callback.helper';
|
package/dist/helpers/index.js
CHANGED
|
@@ -18,4 +18,5 @@ __exportStar(require("./get-env.helper"), exports);
|
|
|
18
18
|
__exportStar(require("./multi-inheritance.helper"), exports);
|
|
19
19
|
__exportStar(require("./message-formatter.helper"), exports);
|
|
20
20
|
__exportStar(require("./convert-string-case.helper"), exports);
|
|
21
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./rxjs-catch-error.helper"), exports);
|
|
22
|
+
__exportStar(require("./rxjs-timeout-custom-callback.helper"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function RxjsCatchErrorHelper(): import("rxjs").OperatorFunction<unknown, unknown>;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RxjsCatchErrorHelper = RxjsCatchErrorHelper;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const exceptions = require("@nestjs/common/exceptions");
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const rxjs_1 = require("rxjs");
|
|
7
|
+
function RxjsCatchErrorHelper() {
|
|
8
|
+
return (0, rxjs_1.catchError)((err) => {
|
|
8
9
|
if (exceptions[err?.name])
|
|
9
10
|
throw new exceptions[err.name](err);
|
|
10
11
|
else if (Object.keys(strapiApplicationErrors).includes(err?.name))
|
|
11
12
|
throw new strapiApplicationErrors[err?.name](err?.response);
|
|
12
13
|
else
|
|
13
14
|
throw new common_1.InternalServerErrorException(err);
|
|
14
|
-
};
|
|
15
|
+
});
|
|
15
16
|
}
|
|
16
17
|
const strapiApplicationErrors = {
|
|
17
18
|
ApplicationError: exceptions.InternalServerErrorException,
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { ObservableInput, ObservedValueOf, OperatorFunction, TimeoutConfig } from 'rxjs';
|
|
2
|
+
export declare function RxjsCustomTimeoutHelper<T, O extends ObservableInput<unknown>, M = unknown>(timeoutSeconds: number, serviceName: string, methodName: string, config?: TimeoutConfig<T, O, M>): OperatorFunction<T, T | ObservedValueOf<O>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RxjsCustomTimeoutHelper = RxjsCustomTimeoutHelper;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const convert_string_case_helper_1 = require("./convert-string-case.helper");
|
|
7
|
+
function RxjsCustomTimeoutHelper(timeoutSeconds, serviceName, methodName, config) {
|
|
8
|
+
return (0, rxjs_1.timeout)({
|
|
9
|
+
each: timeoutSeconds * 1000,
|
|
10
|
+
with: () => (0, rxjs_1.throwError)(() => new common_1.GatewayTimeoutException(`${convert_string_case_helper_1.ConvertStringCaseHelper.camelToKebab(serviceName)}-` +
|
|
11
|
+
`${convert_string_case_helper_1.ConvertStringCaseHelper.camelToKebab(methodName)}: ` +
|
|
12
|
+
`Timeout has occurred`)),
|
|
13
|
+
...config,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -163,8 +163,10 @@ class CoreCrudService {
|
|
|
163
163
|
async update(id, updateDto, options) {
|
|
164
164
|
updateDto = this.relatedPropertyTransformer(updateDto);
|
|
165
165
|
if (!options?.entityManager) {
|
|
166
|
+
const selectFields = Object.keys(updateDto);
|
|
166
167
|
const fetchedItem = await this.repository.findOne({
|
|
167
168
|
where: { id },
|
|
169
|
+
select: ['id', ...selectFields],
|
|
168
170
|
relations: options?.relations ? options?.relations : this.relationsPath,
|
|
169
171
|
});
|
|
170
172
|
if (!fetchedItem)
|
|
@@ -178,9 +180,13 @@ class CoreCrudService {
|
|
|
178
180
|
};
|
|
179
181
|
}
|
|
180
182
|
else {
|
|
183
|
+
const selectFields = Object.keys(updateDto);
|
|
181
184
|
const fetchedItem = await options?.entityManager.findOne(this.repository.target, {
|
|
182
185
|
where: { id },
|
|
183
|
-
|
|
186
|
+
select: ['id', ...selectFields],
|
|
187
|
+
relations: options?.relations
|
|
188
|
+
? options?.relations
|
|
189
|
+
: this.relationsPath,
|
|
184
190
|
});
|
|
185
191
|
if (!fetchedItem)
|
|
186
192
|
throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.snakeToKebab(this.repository.metadata?.tableName)}`));
|