@mondart/nestjs-common-module 1.1.52 → 1.1.54
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/dto/request/index.d.ts +1 -0
- package/dist/dto/request/index.js +1 -0
- package/dist/dto/request/uuid.dto.d.ts +3 -0
- package/dist/dto/request/uuid.dto.js +22 -0
- package/dist/dto/response/error-response.dto.d.ts +2 -2
- package/dist/dto/response/error-response.dto.js +3 -3
- package/dist/dto/response/validation.dto.d.ts +2 -2
- package/dist/dto/response/validation.dto.js +2 -2
- package/dist/services/core-crud.service.js +7 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -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);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UUIDDto = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const decorators_1 = require("../../decorators");
|
|
15
|
+
class UUIDDto {
|
|
16
|
+
}
|
|
17
|
+
exports.UUIDDto = UUIDDto;
|
|
18
|
+
__decorate([
|
|
19
|
+
(0, swagger_1.ApiProperty)({ example: 'f5639d77-d001-40e7-b88b-4ea1e11cf907' }),
|
|
20
|
+
(0, decorators_1.IsUUID)(),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], UUIDDto.prototype, "uuid", void 0);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare class BaseErrorResponse {
|
|
2
2
|
message: string;
|
|
3
|
-
|
|
3
|
+
status: number;
|
|
4
4
|
details: Record<string, any>;
|
|
5
5
|
}
|
|
6
6
|
export declare class ErrorResponse extends BaseErrorResponse {
|
|
7
|
-
constructor(message: string,
|
|
7
|
+
constructor(message: string, status: number, details?: any);
|
|
8
8
|
}
|
|
@@ -21,16 +21,16 @@ __decorate([
|
|
|
21
21
|
__decorate([
|
|
22
22
|
(0, swagger_1.ApiProperty)({ type: Number }),
|
|
23
23
|
__metadata("design:type", Number)
|
|
24
|
-
], BaseErrorResponse.prototype, "
|
|
24
|
+
], BaseErrorResponse.prototype, "status", void 0);
|
|
25
25
|
__decorate([
|
|
26
26
|
(0, swagger_1.ApiProperty)(),
|
|
27
27
|
__metadata("design:type", Object)
|
|
28
28
|
], BaseErrorResponse.prototype, "details", void 0);
|
|
29
29
|
class ErrorResponse extends BaseErrorResponse {
|
|
30
|
-
constructor(message,
|
|
30
|
+
constructor(message, status, details = {}) {
|
|
31
31
|
super();
|
|
32
32
|
this.message = message;
|
|
33
|
-
this.
|
|
33
|
+
this.status = status;
|
|
34
34
|
this.details = details;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -9,12 +9,12 @@ declare class ValidationMsg {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class ValidationErrorResponseType {
|
|
11
11
|
message: string;
|
|
12
|
-
|
|
12
|
+
status: string;
|
|
13
13
|
validationMsg: ValidationMsg;
|
|
14
14
|
}
|
|
15
15
|
export declare class ValidationErrorResponseDto {
|
|
16
16
|
message: string;
|
|
17
|
-
|
|
17
|
+
status: string;
|
|
18
18
|
validationMsg: object;
|
|
19
19
|
constructor(message: string, error: {
|
|
20
20
|
validationErrors?: Array<ValidationError>;
|
|
@@ -46,7 +46,7 @@ __decorate([
|
|
|
46
46
|
__decorate([
|
|
47
47
|
(0, swagger_1.ApiProperty)({ type: String }),
|
|
48
48
|
__metadata("design:type", String)
|
|
49
|
-
], ValidationErrorResponseType.prototype, "
|
|
49
|
+
], ValidationErrorResponseType.prototype, "status", void 0);
|
|
50
50
|
__decorate([
|
|
51
51
|
(0, swagger_1.ApiProperty)({ type: ValidationMsg }),
|
|
52
52
|
__metadata("design:type", ValidationMsg)
|
|
@@ -65,7 +65,7 @@ class ValidationErrorResponseDto {
|
|
|
65
65
|
});
|
|
66
66
|
validation = validation || error.errors;
|
|
67
67
|
this.message = message;
|
|
68
|
-
this.
|
|
68
|
+
this.status = String(common_1.HttpStatus.BAD_REQUEST);
|
|
69
69
|
this.validationMsg = {
|
|
70
70
|
errors: validation,
|
|
71
71
|
};
|
|
@@ -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)}`));
|