From 9bd598da31f5e244a935429ad5872a3cfd2581b7 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Tue, 29 Oct 2024 16:33:57 +0400 Subject: [PATCH] added success message --- libs/common/src/dto/success.response.dto.ts | 1 + src/community/services/community.service.ts | 16 +++------------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/libs/common/src/dto/success.response.dto.ts b/libs/common/src/dto/success.response.dto.ts index f21bf78..64cd0c4 100644 --- a/libs/common/src/dto/success.response.dto.ts +++ b/libs/common/src/dto/success.response.dto.ts @@ -23,6 +23,7 @@ export class SuccessResponseDto implements BaseResponseDto { constructor(input: BaseResponseDto) { if (input.statusCode) this.statusCode = input.statusCode; else this.statusCode = 200; + if (input.message) this.message = input.message; if (input.data) this.data = input.data; this.success = true; } diff --git a/src/community/services/community.service.ts b/src/community/services/community.service.ts index ba0e6f9..7080c3e 100644 --- a/src/community/services/community.service.ts +++ b/src/community/services/community.service.ts @@ -109,15 +109,10 @@ export class CommunityService { try { const { name } = updateCommunityDto; - // Find the community by its UUID - - // Update the community name community.name = name; - // Save the updated community back to the database const updatedCommunity = await this.communityRepository.save(community); - // Return a SuccessResponseDto with the updated community data return new SuccessResponseDto({ message: 'Success update Community', data: updatedCommunity, @@ -146,19 +141,14 @@ export class CommunityService { ); } try { - // Find the community by its uuid + await this.communityRepository.remove(community); - // Remove the community from the database - - // Return success response return new SuccessResponseDto({ - message: `Community with ID ${communityUuid} successfully deleted`, - data: null, + message: `Community with ID ${communityUuid} has been successfully deleted`, }); } catch (err) { - // Catch and handle any errors if (err instanceof HttpException) { - throw err; // If it's an HttpException, rethrow it + throw err; } else { throw new HttpException( 'An error occurred while deleting the community',