kaneo (minimalist kanban) fork to experiment adding a tangled integration
github.com/usekaneo/kaneo
1import { eq } from "drizzle-orm";
2import { HTTPException } from "hono/http-exception";
3import db from "../../database";
4import { projectTable, taskTable, userTable } from "../../database/schema";
5
6async function exportTasks(projectId: string) {
7 const project = await db.query.projectTable.findFirst({
8 where: eq(projectTable.id, projectId),
9 });
10
11 if (!project) {
12 throw new HTTPException(404, {
13 message: "Project not found",
14 });
15 }
16
17 const tasks = await db
18 .select({
19 id: taskTable.id,
20 title: taskTable.title,
21 number: taskTable.number,
22 description: taskTable.description,
23 status: taskTable.status,
24 priority: taskTable.priority,
25 dueDate: taskTable.dueDate,
26 position: taskTable.position,
27 createdAt: taskTable.createdAt,
28 userId: taskTable.userId,
29 assigneeName: userTable.name,
30 assigneeId: userTable.id,
31 })
32 .from(taskTable)
33 .leftJoin(userTable, eq(taskTable.userId, userTable.id))
34 .where(eq(taskTable.projectId, projectId))
35 .orderBy(taskTable.position);
36
37 return {
38 project: {
39 name: project.name,
40 slug: project.slug,
41 description: project.description,
42 exportedAt: new Date().toISOString(),
43 },
44 tasks: tasks.map((task) => ({
45 title: task.title,
46 description: task.description || "",
47 status: task.status,
48 priority: task.priority || "low",
49 dueDate: task.dueDate ? new Date(task.dueDate).toISOString() : null,
50 userId: task.userId || null,
51 })),
52 };
53}
54
55export default exportTasks;