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";
5
6async function updateTask(
7 id: string,
8 title: string,
9 status: string,
10 dueDate: Date | undefined,
11 projectId: string,
12 description: string,
13 priority: string,
14 position: number,
15 userId?: string,
16) {
17 const existingTask = await db.query.taskTable.findFirst({
18 where: eq(taskTable.id, id),
19 });
20
21 if (!existingTask) {
22 throw new HTTPException(404, {
23 message: "Task not found",
24 });
25 }
26
27 const column = await db.query.columnTable.findFirst({
28 where: and(
29 eq(columnTable.projectId, projectId),
30 eq(columnTable.slug, status),
31 ),
32 });
33
34 const [updatedTask] = await db
35 .update(taskTable)
36 .set({
37 title,
38 status,
39 columnId: column?.id ?? null,
40 dueDate: dueDate || null,
41 projectId,
42 description,
43 priority,
44 position,
45 userId: userId || null,
46 })
47 .where(eq(taskTable.id, id))
48 .returning();
49
50 if (!updatedTask) {
51 throw new HTTPException(500, {
52 message: "Failed to update task",
53 });
54 }
55
56 return updatedTask;
57}
58
59export default updateTask;