Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(pr): responding to AI pr reviews

justincb2f3337d513
diff --git a/apps/api/src/task/controllers/create-task.ts b/apps/api/src/task/controllers/create-task.ts
index f4d0c675c..3c09065df 100644
--- a/apps/api/src/task/controllers/create-task.ts
+++ b/apps/api/src/task/controllers/create-task.ts
@@ -30,14 +30,22 @@ async function createTask({
const resolvedStatus = status || "to-do";
const resolvedPriority = priority || "no-priority";
+ const normalizedUserId = userId?.trim();
+
+ if (userId !== undefined && normalizedUserId === "") {
+ throw new HTTPException(400, {
+ message: "Assignee id cannot be empty",
+ });
+ }
+
await assertValidTaskStatus(resolvedStatus, projectId);
const [assignee] = await db
.select({ name: userTable.name })
.from(userTable)
- .where(eq(userTable.id, userId ?? ""));
+ .where(eq(userTable.id, normalizedUserId ?? ""));
- if (userId && !assignee) {
+ if (normalizedUserId && !assignee) {
throw new HTTPException(404, {
message: "Assignee not found",
});
@@ -71,7 +79,7 @@ async function createTask({
.insert(taskTable)
.values({
projectId,
- userId: userId || null,
+ userId: normalizedUserId ?? null,
title: title || "",
status: resolvedStatus,
columnId: column?.id ?? null,
diff --git a/apps/api/src/task/index.ts b/apps/api/src/task/index.ts
index d984a02fe..dde52831c 100644
--- a/apps/api/src/task/index.ts
+++ b/apps/api/src/task/index.ts
@@ -196,7 +196,7 @@ const task = new Hono<{
dueDate: v.optional(v.string()),
priority: v.picklist(VALID_PRIORITIES),
status: v.string(),
- userId: v.optional(v.string()),
+ userId: v.optional(v.pipe(v.string(), v.minLength(1))),
}),
),
workspaceAccess.fromProject("projectId"),
diff --git a/tests/api-integration/task.test.ts b/tests/api-integration/task.test.ts
index a06a37ffa..9368ed6ef 100644
--- a/tests/api-integration/task.test.ts
+++ b/tests/api-integration/task.test.ts
@@ -280,4 +280,41 @@ describe("API integration: task creation", () => {
position: 1,
});
});
+
+ it("rejects task creation when the assignee userId does not exist", async () => {
+ const member = await createWorkspaceMember();
+ const { project } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ const missingAssigneeId = `user-${randomUUID()}`;
+
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+
+ const response = await app.request(`/api/task/${project.id}`, {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ },
+ body: JSON.stringify({
+ title: "Ghost assignee task",
+ description: "Should fail because the assignee does not exist",
+ priority: "low",
+ status: "to-do",
+ userId: missingAssigneeId,
+ }),
+ });
+
+ expect(response.status).toBe(404);
+ await expect(response.text()).resolves.toContain("Assignee not found");
+
+ const persistedTask = await db.query.taskTable.findFirst({
+ where: and(
+ eq(schema.taskTable.projectId, project.id),
+ eq(schema.taskTable.title, "Ghost assignee task"),
+ ),
+ });
+
+ expect(persistedTask).toBeUndefined();
+ });
});