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

View File

@@ -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(
{
name: workspaceName,
type,
description: workspaceDescription,
orgId: organization.id,
slug: projectSlug || slugify(`${workspaceName}-${alphaNumericNanoId(4)}`),
slug,
kmsSecretManagerKeyId: kmsKeyId,
version: ProjectVersion.V3,
pitVersionLimit: 10