mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 09:04:54 +00:00
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 project = await this.validateProject(param.projectUuid);
|
||||||
|
|
||||||
const existingCommunity = await this.communityRepository.findOneBy({
|
await this.validateName(name);
|
||||||
name,
|
|
||||||
});
|
|
||||||
if (existingCommunity) {
|
|
||||||
throw new HttpException(
|
|
||||||
`A community with the name '${name}' already exists.`,
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the new community entity
|
// Create the new community entity
|
||||||
const community = this.communityRepository.create({
|
const community = this.communityRepository.create({
|
||||||
@ -148,6 +140,7 @@ export class CommunityService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { name } = updateCommunityDto;
|
const { name } = updateCommunityDto;
|
||||||
|
if (name != community.name) await this.validateName(name);
|
||||||
|
|
||||||
community.name = name;
|
community.name = name;
|
||||||
|
|
||||||
@ -163,7 +156,10 @@ export class CommunityService {
|
|||||||
throw err; // If it's an HttpException, rethrow it
|
throw err; // If it's an HttpException, rethrow it
|
||||||
} else {
|
} else {
|
||||||
// Throw a generic 404 error if anything else goes wrong
|
// 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;
|
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