working leantime widget 16
This commit is contained in:
parent
e114d647ae
commit
0372dd7aed
@ -133,27 +133,46 @@ export async function GET() {
|
||||
projectsData.result.map((project: any) => [project.id, project.name])
|
||||
);
|
||||
|
||||
// Transform and categorize the tasks
|
||||
const tasks = data.result.map((task: any) => {
|
||||
const dueDate = task.dateToFinish ? new Date(task.dateToFinish * 1000) : null;
|
||||
// Transform the nested structure into a flat array of tasks
|
||||
const tasks: Task[] = [];
|
||||
Object.entries(data.result).forEach(([projectId, statusGroups]) => {
|
||||
const projectName = projectsMap.get(Number(projectId)) || `Project ${projectId}`;
|
||||
|
||||
return {
|
||||
id: task.id,
|
||||
headline: task.headline,
|
||||
projectName: projectsMap.get(task.projectId) || `Project ${task.projectId}`,
|
||||
status: task.status,
|
||||
dueDate: dueDate ? dueDate.toISOString() : null,
|
||||
details: task.description,
|
||||
milestone: task.milestoneName
|
||||
};
|
||||
if (typeof statusGroups === 'object' && statusGroups !== null) {
|
||||
// Iterate through each status group
|
||||
Object.entries(statusGroups).forEach(([statusType, statusLabels]) => {
|
||||
if (typeof statusLabels === 'object' && statusLabels !== null) {
|
||||
// Each status label in the group
|
||||
Object.values(statusLabels).forEach((label: any) => {
|
||||
const headline = String(label.name || label.title || 'Untitled');
|
||||
tasks.push({
|
||||
id: label.id?.toString() || `${projectId}-${statusType}`,
|
||||
headline,
|
||||
projectName,
|
||||
status: label.type || statusType,
|
||||
dueDate: null, // Status labels don't have due dates
|
||||
details: label.description || null,
|
||||
milestone: label.milestone || null
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Sort tasks by due date
|
||||
tasks.sort((a: Task, b: Task) => {
|
||||
if (!a.dueDate && !b.dueDate) return 0;
|
||||
if (!a.dueDate) return 1;
|
||||
if (!b.dueDate) return -1;
|
||||
return new Date(a.dueDate).getTime() - new Date(b.dueDate).getTime();
|
||||
// Sort tasks by status type
|
||||
const statusOrder: Record<string, number> = {
|
||||
'new': 1,
|
||||
'in progress': 2,
|
||||
'waiting': 3,
|
||||
'done': 4,
|
||||
'archived': 5
|
||||
};
|
||||
|
||||
tasks.sort((a, b) => {
|
||||
const statusA = statusOrder[a.status.toLowerCase()] || 99;
|
||||
const statusB = statusOrder[b.status.toLowerCase()] || 99;
|
||||
return statusA - statusB;
|
||||
});
|
||||
|
||||
return NextResponse.json({ tasks });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user