added success message

This commit is contained in:
hannathkadher
2024-10-29 16:33:57 +04:00
parent d6e6eb9b1f
commit 9bd598da31
2 changed files with 4 additions and 13 deletions

View File

@ -23,6 +23,7 @@ export class SuccessResponseDto<Type> implements BaseResponseDto {
constructor(input: BaseResponseDto) { constructor(input: BaseResponseDto) {
if (input.statusCode) this.statusCode = input.statusCode; if (input.statusCode) this.statusCode = input.statusCode;
else this.statusCode = 200; else this.statusCode = 200;
if (input.message) this.message = input.message;
if (input.data) this.data = input.data; if (input.data) this.data = input.data;
this.success = true; this.success = true;
} }

View File

@ -109,15 +109,10 @@ export class CommunityService {
try { try {
const { name } = updateCommunityDto; const { name } = updateCommunityDto;
// Find the community by its UUID
// Update the community name
community.name = name; community.name = name;
// Save the updated community back to the database
const updatedCommunity = await this.communityRepository.save(community); const updatedCommunity = await this.communityRepository.save(community);
// Return a SuccessResponseDto with the updated community data
return new SuccessResponseDto<CommunityDto>({ return new SuccessResponseDto<CommunityDto>({
message: 'Success update Community', message: 'Success update Community',
data: updatedCommunity, data: updatedCommunity,
@ -146,19 +141,14 @@ export class CommunityService {
); );
} }
try { try {
// Find the community by its uuid await this.communityRepository.remove(community);
// Remove the community from the database
// Return success response
return new SuccessResponseDto({ return new SuccessResponseDto({
message: `Community with ID ${communityUuid} successfully deleted`, message: `Community with ID ${communityUuid} has been successfully deleted`,
data: null,
}); });
} catch (err) { } catch (err) {
// Catch and handle any errors
if (err instanceof HttpException) { if (err instanceof HttpException) {
throw err; // If it's an HttpException, rethrow it throw err;
} else { } else {
throw new HttpException( throw new HttpException(
'An error occurred while deleting the community', 'An error occurred while deleting the community',