/** * @file dashboard/page.tsx * @description Server component rendering the main dashboard page using the TaskService. */ import { auth } from "@/auth"; import { redirect } from "next/navigation"; import Board from "./Board"; import { Task } from "@/types/tasks"; import { TaskService } from "@/services/task.service"; /** * Renders the dashboard page component with user session validation, * optimized database queries for active tasks, and team assignees. * * @async * @returns {Promise} The rendered dashboard page component. */ export default async function Dashboard() { const session = await auth(); if (!session?.user?.id) redirect("/login"); const currentUserId = session.user.id; const rawTasksWithCreator = await TaskService.findActiveTasksForUser(currentUserId); const allTaskIds = rawTasksWithCreator.map((item) => item.task.id); const assigneesData = await TaskService.findAssigneesForTasks(allTaskIds); const assigneesMap = new Map(); for (const row of assigneesData) { const existing = assigneesMap.get(row.taskId) || []; assigneesMap.set(row.taskId, [...existing, row.email]); } const tasks: Task[] = rawTasksWithCreator.map(({ task, creatorEmail }) => ({ ...task, creator: creatorEmail, assignees: assigneesMap.get(task.id) || [], isCreator: task.userId === currentUserId, })); return (
); }