kaneo (minimalist kanban) fork to experiment adding a tangled integration
github.com/usekaneo/kaneo
1import { eq } from "drizzle-orm";
2import db from "../../database";
3import { projectTable } from "../../database/schema";
4
5async function getProjects(workspaceId: string) {
6 const projects = await db.query.projectTable.findMany({
7 where: eq(projectTable.workspaceId, workspaceId),
8 with: {
9 tasks: true,
10 },
11 });
12
13 const projectsWithStatistics = projects.map((project) => {
14 const totalTasks = project.tasks.length;
15 const completedTasks = project.tasks.filter(
16 (task) => task.status === "done" || task.status === "archived",
17 ).length;
18 const completionPercentage =
19 totalTasks > 0 ? Math.round((completedTasks / totalTasks) * 100) : 0;
20
21 const dueDate = project.tasks.reduce((earliest: Date | null, task) => {
22 if (!earliest || (task.dueDate && task.dueDate < earliest))
23 return task.dueDate;
24 return earliest;
25 }, null);
26
27 return {
28 ...project,
29 statistics: {
30 completionPercentage,
31 totalTasks,
32 dueDate,
33 },
34 archivedTasks: [],
35 plannedTasks: [],
36 columns: [],
37 };
38 });
39
40 return projectsWithStatistics;
41}
42
43export default getProjects;