feat(project-service): add unique slug check when creating project

This commit is contained in:
Piyush Gupta
2025-10-25 01:56:13 +05:30
parent 3ea4ebe101
commit a35dc858ba
@@ -303,13 +303,26 @@ export const projectServiceFactory = ({
}); });
} }
const slug = projectSlug || slugify(`${workspaceName}-${alphaNumericNanoId(4)}`);
const existingProject = await projectDAL.findOne({
slug,
orgId: organization.id
});
if (existingProject) {
throw new BadRequestError({
message: `Failed to create project. A project with the slug "${slug}" already exists in your organization. Please choose a different name or slug.`
});
}
const project = await projectDAL.create( const project = await projectDAL.create(
{ {
name: workspaceName, name: workspaceName,
type, type,
description: workspaceDescription, description: workspaceDescription,
orgId: organization.id, orgId: organization.id,
slug: projectSlug || slugify(`${workspaceName}-${alphaNumericNanoId(4)}`), slug,
kmsSecretManagerKeyId: kmsKeyId, kmsSecretManagerKeyId: kmsKeyId,
version: ProjectVersion.V3, version: ProjectVersion.V3,
pitVersionLimit: 10 pitVersionLimit: 10