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 } from "../../database/schema";
5
6async function reorderColumns(
7 projectId: string,
8 columns: Array<{ id: string; position: number }>,
9) {
10 for (const col of columns) {
11 const [updated] = await db
12 .update(columnTable)
13 .set({ position: col.position })
14 .where(
15 and(eq(columnTable.id, col.id), eq(columnTable.projectId, projectId)),
16 )
17 .returning({ id: columnTable.id });
18
19 if (!updated) {
20 throw new HTTPException(400, {
21 message: `Column ${col.id} does not belong to this project`,
22 });
23 }
24 }
25
26 const updated = await db.query.columnTable.findMany({
27 where: eq(columnTable.projectId, projectId),
28 orderBy: (columns, { asc }) => [asc(columns.position)],
29 });
30
31 return updated;
32}
33
34export default reorderColumns;