kaneo (minimalist kanban) fork to experiment adding a tangled integration github.com/usekaneo/kaneo
at main 32 lines 862 B view raw
1import { eq, sql } from "drizzle-orm"; 2import { HTTPException } from "hono/http-exception"; 3import db from "../../database"; 4import { columnTable, taskTable } from "../../database/schema"; 5 6async function deleteColumn(id: string) { 7 const existing = await db.query.columnTable.findFirst({ 8 where: eq(columnTable.id, id), 9 }); 10 11 if (!existing) { 12 throw new HTTPException(404, { message: "Column not found" }); 13 } 14 15 const [taskCount] = await db 16 .select({ count: sql<number>`count(*)` }) 17 .from(taskTable) 18 .where(eq(taskTable.columnId, id)); 19 20 if (taskCount && taskCount.count > 0) { 21 throw new HTTPException(409, { 22 message: 23 "Cannot delete column that contains tasks. Move or delete tasks first.", 24 }); 25 } 26 27 await db.delete(columnTable).where(eq(columnTable.id, id)); 28 29 return existing; 30} 31 32export default deleteColumn;