kaneo (minimalist kanban) fork to experiment adding a tangled integration github.com/usekaneo/kaneo
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 9a620ba2f31238f03cd28f1da5ef3838d67e4e8a 48 lines 1.3 kB view raw
1import { and, eq, isNull } from "drizzle-orm"; 2import db from "../../database"; 3import { projectTable } from "../../database/schema"; 4 5async function getProjects(workspaceId: string, includeArchived = false) { 6 const projects = await db.query.projectTable.findMany({ 7 where: includeArchived 8 ? eq(projectTable.workspaceId, workspaceId) 9 : and( 10 eq(projectTable.workspaceId, workspaceId), 11 isNull(projectTable.archivedAt), 12 ), 13 with: { 14 tasks: true, 15 }, 16 }); 17 18 const projectsWithStatistics = projects.map((project) => { 19 const totalTasks = project.tasks.length; 20 const completedTasks = project.tasks.filter( 21 (task) => task.status === "done" || task.status === "archived", 22 ).length; 23 const completionPercentage = 24 totalTasks > 0 ? Math.round((completedTasks / totalTasks) * 100) : 0; 25 26 const dueDate = project.tasks.reduce((earliest: Date | null, task) => { 27 if (!earliest || (task.dueDate && task.dueDate < earliest)) 28 return task.dueDate; 29 return earliest; 30 }, null); 31 32 return { 33 ...project, 34 statistics: { 35 completionPercentage, 36 totalTasks, 37 dueDate, 38 }, 39 archivedTasks: [], 40 plannedTasks: [], 41 columns: [], 42 }; 43 }); 44 45 return projectsWithStatistics; 46} 47 48export default getProjects;