@mondart/nestjs-common-module 1.1.59 → 1.1.61
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/dto/response/error-response.dto.d.ts +9 -1
- package/dist/dto/response/error-response.dto.js +6 -1
- package/dist/dto/response/kafka-failed-response.dto.js +15 -3
- package/dist/filters/global-exception.filter.js +12 -24
- package/dist/helpers/convert-string-case.helper.d.ts +6 -3
- package/dist/helpers/convert-string-case.helper.js +32 -7
- package/dist/helpers/rxjs-catch-error.helper.js +2 -2
- package/dist/helpers/rxjs-timeout-custom-callback.helper.js +2 -2
- package/dist/lib/caching/caching.service.js +1 -1
- package/dist/services/core-crud.service.js +5 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/validators/validation-options.js +1 -2
- package/package.json +1 -1
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
export declare class BaseErrorResponse {
|
|
2
|
+
name: string;
|
|
2
3
|
message: string;
|
|
3
4
|
status: number;
|
|
4
5
|
details: Record<string, any>;
|
|
5
6
|
}
|
|
7
|
+
interface ErrorResponseParamsInterface {
|
|
8
|
+
name: string;
|
|
9
|
+
message: string;
|
|
10
|
+
status: number;
|
|
11
|
+
details?: any;
|
|
12
|
+
}
|
|
6
13
|
export declare class ErrorResponse extends BaseErrorResponse {
|
|
7
|
-
constructor(
|
|
14
|
+
constructor({ name, message, status, details, }: ErrorResponseParamsInterface);
|
|
8
15
|
}
|
|
16
|
+
export {};
|
|
@@ -14,6 +14,10 @@ const swagger_1 = require("@nestjs/swagger");
|
|
|
14
14
|
class BaseErrorResponse {
|
|
15
15
|
}
|
|
16
16
|
exports.BaseErrorResponse = BaseErrorResponse;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, swagger_1.ApiProperty)({ type: String }),
|
|
19
|
+
__metadata("design:type", String)
|
|
20
|
+
], BaseErrorResponse.prototype, "name", void 0);
|
|
17
21
|
__decorate([
|
|
18
22
|
(0, swagger_1.ApiProperty)({ type: String }),
|
|
19
23
|
__metadata("design:type", String)
|
|
@@ -27,8 +31,9 @@ __decorate([
|
|
|
27
31
|
__metadata("design:type", Object)
|
|
28
32
|
], BaseErrorResponse.prototype, "details", void 0);
|
|
29
33
|
class ErrorResponse extends BaseErrorResponse {
|
|
30
|
-
constructor(message, status, details = {}) {
|
|
34
|
+
constructor({ name, message, status, details = {}, }) {
|
|
31
35
|
super();
|
|
36
|
+
this.name = name;
|
|
32
37
|
this.message = message;
|
|
33
38
|
this.status = status;
|
|
34
39
|
this.details = details;
|
|
@@ -19,17 +19,29 @@ class KafkaFailedResponseDto extends base_kafka_error_response_dto_1.BaseKafkaEr
|
|
|
19
19
|
}
|
|
20
20
|
notFound(message) {
|
|
21
21
|
this.status = common_1.HttpStatus.NOT_FOUND;
|
|
22
|
-
this.data = new error_response_dto_1.ErrorResponse(
|
|
22
|
+
this.data = new error_response_dto_1.ErrorResponse({
|
|
23
|
+
name: common_1.NotFoundException.name,
|
|
24
|
+
message: helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, message),
|
|
25
|
+
status: this.status,
|
|
26
|
+
});
|
|
23
27
|
return this;
|
|
24
28
|
}
|
|
25
29
|
badRequest(message) {
|
|
26
30
|
this.status = common_1.HttpStatus.BAD_REQUEST;
|
|
27
|
-
this.data = new error_response_dto_1.ErrorResponse(
|
|
31
|
+
this.data = new error_response_dto_1.ErrorResponse({
|
|
32
|
+
name: common_1.BadRequestException.name,
|
|
33
|
+
message: helpers_1.MessageFormatter.replace(enums_1.SharedMessages.PARAMETER_VALIDATION_FAILED, message),
|
|
34
|
+
status: this.status,
|
|
35
|
+
});
|
|
28
36
|
return this;
|
|
29
37
|
}
|
|
30
38
|
internalServer(message) {
|
|
31
39
|
this.status = common_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
32
|
-
this.data = new error_response_dto_1.ErrorResponse(
|
|
40
|
+
this.data = new error_response_dto_1.ErrorResponse({
|
|
41
|
+
name: common_1.InternalServerErrorException.name,
|
|
42
|
+
message: helpers_1.MessageFormatter.replace(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, message),
|
|
43
|
+
status: this.status,
|
|
44
|
+
});
|
|
33
45
|
return this;
|
|
34
46
|
}
|
|
35
47
|
stringify() {
|
|
@@ -45,33 +45,21 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
|
|
|
45
45
|
try {
|
|
46
46
|
const status = exception?.getStatus();
|
|
47
47
|
const result = exception.getResponse();
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
else if (status === common_1.HttpStatus.BAD_REQUEST) {
|
|
52
|
-
return response
|
|
53
|
-
.status(status)
|
|
54
|
-
.json(new dto_1.ErrorResponse(String(result?.error), status, typeof result?.message === 'string'
|
|
48
|
+
return response.status(status).json(new dto_1.ErrorResponse({
|
|
49
|
+
name: helpers_1.ConvertStringCaseHelper.toTitleCase(exception?.name),
|
|
50
|
+
message: typeof result?.message === 'string'
|
|
55
51
|
? result?.message
|
|
56
|
-
: result?.message
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (typeof result.message === 'string') {
|
|
61
|
-
message = result?.message;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
message = result?.message[0];
|
|
65
|
-
}
|
|
66
|
-
return response
|
|
67
|
-
.status(status)
|
|
68
|
-
.json(new dto_1.ErrorResponse(message, status));
|
|
69
|
-
}
|
|
52
|
+
: result?.message.join(', '),
|
|
53
|
+
status: status,
|
|
54
|
+
details: exception?.options ?? {},
|
|
55
|
+
}));
|
|
70
56
|
}
|
|
71
57
|
catch (err) {
|
|
72
|
-
response
|
|
73
|
-
|
|
74
|
-
|
|
58
|
+
response.status(common_1.HttpStatus.INTERNAL_SERVER_ERROR).json(new dto_1.ErrorResponse({
|
|
59
|
+
name: common_1.InternalServerErrorException.name,
|
|
60
|
+
message: helpers_1.MessageFormatter.replace(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, exception?.message),
|
|
61
|
+
status: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
62
|
+
}));
|
|
75
63
|
}
|
|
76
64
|
}
|
|
77
65
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export declare class ConvertStringCaseHelper {
|
|
2
|
-
static
|
|
3
|
-
static
|
|
4
|
-
static
|
|
2
|
+
static toKebabCase(str: string): string;
|
|
3
|
+
static toCamelCase(str: string): string;
|
|
4
|
+
static toPascalCase(str: string): string;
|
|
5
|
+
static toSnakeCase(str: string): string;
|
|
6
|
+
static toSpaceSeparated(str: string): string;
|
|
7
|
+
static toTitleCase(str: string): string;
|
|
5
8
|
}
|
|
@@ -2,17 +2,42 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConvertStringCaseHelper = void 0;
|
|
4
4
|
class ConvertStringCaseHelper {
|
|
5
|
-
static
|
|
5
|
+
static toKebabCase(str) {
|
|
6
6
|
return str
|
|
7
|
-
.replace(/([
|
|
8
|
-
.replace(/
|
|
7
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
8
|
+
.replace(/[\s_]+/g, '-')
|
|
9
9
|
.toLowerCase();
|
|
10
10
|
}
|
|
11
|
-
static
|
|
12
|
-
return str
|
|
11
|
+
static toCamelCase(str) {
|
|
12
|
+
return str
|
|
13
|
+
.replace(/[-_\s]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : ''))
|
|
14
|
+
.replace(/^[A-Z]/, (chr) => chr.toLowerCase());
|
|
15
|
+
}
|
|
16
|
+
static toPascalCase(str) {
|
|
17
|
+
return str
|
|
18
|
+
.replace(/[-_\s]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : ''))
|
|
19
|
+
.replace(/^[a-z]/, (chr) => chr.toUpperCase());
|
|
20
|
+
}
|
|
21
|
+
static toSnakeCase(str) {
|
|
22
|
+
return str
|
|
23
|
+
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
24
|
+
.replace(/[-\s]+/g, '_')
|
|
25
|
+
.toLowerCase();
|
|
13
26
|
}
|
|
14
|
-
static
|
|
15
|
-
return str
|
|
27
|
+
static toSpaceSeparated(str) {
|
|
28
|
+
return str
|
|
29
|
+
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
30
|
+
.replace(/[-_]+/g, ' ')
|
|
31
|
+
.toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
static toTitleCase(str) {
|
|
34
|
+
return str
|
|
35
|
+
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
36
|
+
.replace(/[-_]+/g, ' ')
|
|
37
|
+
.toLowerCase()
|
|
38
|
+
.split(' ')
|
|
39
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
40
|
+
.join(' ');
|
|
16
41
|
}
|
|
17
42
|
}
|
|
18
43
|
exports.ConvertStringCaseHelper = ConvertStringCaseHelper;
|
|
@@ -9,9 +9,9 @@ function RxjsCatchErrorHelper() {
|
|
|
9
9
|
if (exceptions[err?.name])
|
|
10
10
|
throw new exceptions[err.name](err?.response);
|
|
11
11
|
else if (Object.keys(strapiApplicationErrors).includes(err?.name))
|
|
12
|
-
throw new strapiApplicationErrors[err?.name](err?.
|
|
12
|
+
throw new strapiApplicationErrors[err?.name](err?.err?.message ?? err?.message, err?.err?.details ?? err?.details);
|
|
13
13
|
else
|
|
14
|
-
throw new common_1.InternalServerErrorException(err);
|
|
14
|
+
throw new common_1.InternalServerErrorException(err?.response ?? err);
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
const strapiApplicationErrors = {
|
|
@@ -7,8 +7,8 @@ const convert_string_case_helper_1 = require("./convert-string-case.helper");
|
|
|
7
7
|
function RxjsCustomTimeoutHelper(timeoutSeconds, serviceName, methodName, config) {
|
|
8
8
|
return (0, rxjs_1.timeout)({
|
|
9
9
|
each: timeoutSeconds * 1000,
|
|
10
|
-
with: () => (0, rxjs_1.throwError)(() => new common_1.GatewayTimeoutException(`${convert_string_case_helper_1.ConvertStringCaseHelper.
|
|
11
|
-
`${convert_string_case_helper_1.ConvertStringCaseHelper.
|
|
10
|
+
with: () => (0, rxjs_1.throwError)(() => new common_1.GatewayTimeoutException(`${convert_string_case_helper_1.ConvertStringCaseHelper.toKebabCase(serviceName)}-` +
|
|
11
|
+
`${convert_string_case_helper_1.ConvertStringCaseHelper.toKebabCase(methodName)}: ` +
|
|
12
12
|
`Timeout has occurred`)),
|
|
13
13
|
...config,
|
|
14
14
|
});
|
|
@@ -30,7 +30,7 @@ let CachingService = class CachingService {
|
|
|
30
30
|
return undefined;
|
|
31
31
|
}
|
|
32
32
|
async set(key, value, ttlSeconds) {
|
|
33
|
-
await this.cacheManager.set(key, JSON.stringify(value), ttlSeconds);
|
|
33
|
+
await this.cacheManager.set(key, JSON.stringify(value), ttlSeconds * 1000);
|
|
34
34
|
}
|
|
35
35
|
async del(key) {
|
|
36
36
|
await this.cacheManager.del(key);
|
|
@@ -42,7 +42,7 @@ class CoreCrudService {
|
|
|
42
42
|
...query,
|
|
43
43
|
});
|
|
44
44
|
if (options?.existsCheck && !result) {
|
|
45
|
-
throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.
|
|
45
|
+
throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.toKebabCase(this.repository.metadata?.tableName)}`));
|
|
46
46
|
}
|
|
47
47
|
return result;
|
|
48
48
|
}
|
|
@@ -65,7 +65,7 @@ class CoreCrudService {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
if (options?.existsCheck && !result) {
|
|
68
|
-
throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.
|
|
68
|
+
throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.toKebabCase(this.repository.metadata?.tableName)}-id: ${id}`));
|
|
69
69
|
}
|
|
70
70
|
return result;
|
|
71
71
|
}
|
|
@@ -85,7 +85,7 @@ class CoreCrudService {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
if (options?.existsCheck && !result) {
|
|
88
|
-
throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.
|
|
88
|
+
throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.toKebabCase(this.repository.metadata?.tableName)}`));
|
|
89
89
|
}
|
|
90
90
|
return result;
|
|
91
91
|
}
|
|
@@ -170,7 +170,7 @@ class CoreCrudService {
|
|
|
170
170
|
relations: options?.relations ? options?.relations : this.relationsPath,
|
|
171
171
|
});
|
|
172
172
|
if (!fetchedItem)
|
|
173
|
-
throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.
|
|
173
|
+
throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.toKebabCase(this.repository.metadata?.tableName)}`));
|
|
174
174
|
const merged = this.repository.merge(fetchedItem, updateDto);
|
|
175
175
|
await this.repository.save(merged);
|
|
176
176
|
return {
|
|
@@ -189,7 +189,7 @@ class CoreCrudService {
|
|
|
189
189
|
: this.relationsPath,
|
|
190
190
|
});
|
|
191
191
|
if (!fetchedItem)
|
|
192
|
-
throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.
|
|
192
|
+
throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.toKebabCase(this.repository.metadata?.tableName)}`));
|
|
193
193
|
const merged = options?.entityManager.merge(this.repository.target, fetchedItem, updateDto);
|
|
194
194
|
await options?.entityManager.save(merged);
|
|
195
195
|
return {
|