kaneo (minimalist kanban) fork to experiment adding a tangled integration
github.com/usekaneo/kaneo
1import { and, eq } from "drizzle-orm";
2import { HTTPException } from "hono/http-exception";
3import db from "../../database";
4import { columnTable, taskTable } from "../../database/schema";
5import { assertValidTaskStatus } from "../validate-task-fields";
6
7async function updateTask(
8 id: string,
9 title: string,
10 status: string,
11 startDate: Date | undefined,
12 dueDate: Date | undefined,
13 projectId: string,
14 description: string,
15 priority: string,
16 position: number,
17 userId?: string,
18) {
19 const existingTask = await db.query.taskTable.findFirst({
20 where: eq(taskTable.id, id),
21 });
22
23 if (!existingTask) {
24 throw new HTTPException(404, {
25 message: "Task not found",
26 });
27 }
28
29 await assertValidTaskStatus(status, projectId);
30
31 const column = await db.query.columnTable.findFirst({
32 where: and(
33 eq(columnTable.projectId, projectId),
34 eq(columnTable.slug, status),
35 ),
36 });
37
38 const [updatedTask] = await db
39 .update(taskTable)
40 .set({
41 title,
42 status,
43 columnId: column?.id ?? null,
44 startDate: startDate || null,
45 dueDate: dueDate || null,
46 projectId,
47 description,
48 priority,
49 position,
50 userId: userId || null,
51 })
52 .where(eq(taskTable.id, id))
53 .returning();
54
55 if (!updatedTask) {
56 throw new HTTPException(500, {
57 message: "Failed to update task",
58 });
59 }
60
61 return updatedTask;
62}
63
64export default updateTask;