mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
Merge pull request #186 from SyncrowIOT/bugfix/fix-error-on-community-update-error
updated error message for update community with existing name
This commit is contained in:
@ -31,15 +31,7 @@ export class CommunityService {
|
||||
|
||||
const project = await this.validateProject(param.projectUuid);
|
||||
|
||||
const existingCommunity = await this.communityRepository.findOneBy({
|
||||
name,
|
||||
});
|
||||
if (existingCommunity) {
|
||||
throw new HttpException(
|
||||
`A community with the name '${name}' already exists.`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
await this.validateName(name);
|
||||
|
||||
// Create the new community entity
|
||||
const community = this.communityRepository.create({
|
||||
@ -148,6 +140,7 @@ export class CommunityService {
|
||||
|
||||
try {
|
||||
const { name } = updateCommunityDto;
|
||||
if (name != community.name) await this.validateName(name);
|
||||
|
||||
community.name = name;
|
||||
|
||||
@ -163,7 +156,10 @@ export class CommunityService {
|
||||
throw err; // If it's an HttpException, rethrow it
|
||||
} else {
|
||||
// Throw a generic 404 error if anything else goes wrong
|
||||
throw new HttpException('Community not found', HttpStatus.NOT_FOUND);
|
||||
throw new HttpException(
|
||||
`An Internal exception has been occured ${err}`,
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -234,4 +230,16 @@ export class CommunityService {
|
||||
}
|
||||
return project;
|
||||
}
|
||||
|
||||
private async validateName(name: string) {
|
||||
const existingCommunity = await this.communityRepository.findOneBy({
|
||||
name,
|
||||
});
|
||||
if (existingCommunity) {
|
||||
throw new HttpException(
|
||||
`A community with the name '${name}' already exists.`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user