Optional slug on create project

This commit is contained in:
Daniel Hougaard
2024-02-22 05:00:26 +01:00
parent a0e25b8ea2
commit ae3606c9fb
+11 -1
View File
@@ -1,3 +1,4 @@
import slugify from "@sindresorhus/slugify";
import { z } from "zod"; import { z } from "zod";
import { ProjectKeysSchema, ProjectsSchema } from "@app/db/schemas"; import { ProjectKeysSchema, ProjectsSchema } from "@app/db/schemas";
@@ -125,6 +126,14 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
schema: { schema: {
body: z.object({ body: z.object({
projectName: z.string().trim(), projectName: z.string().trim(),
slug: z
.string()
.min(5)
.max(36)
.refine((v) => slugify(v) === v, {
message: "Slug must be a valid slug"
})
.optional(),
organizationId: z.string().trim() organizationId: z.string().trim()
}), }),
response: { response: {
@@ -139,7 +148,8 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
actorId: req.permission.id, actorId: req.permission.id,
actor: req.permission.type, actor: req.permission.type,
orgId: req.body.organizationId, orgId: req.body.organizationId,
workspaceName: req.body.projectName workspaceName: req.body.projectName,
slug: req.body.slug
}); });
return { project }; return { project };