@mondart/nestjs-common-module 1.1.53 → 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.
|
@@ -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);
|
|
@@ -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)}`));
|