working leantime widget 17

This commit is contained in:
Alma 2025-04-12 13:29:53 +02:00
parent 0372dd7aed
commit 742f436ff8

View File

@ -104,7 +104,7 @@ export async function GET() {
}
const data = await response.json();
console.log('Tasks response:', data);
console.log('Tasks response:', JSON.stringify(data, null, 2));
if (!data.result) {
return NextResponse.json({ tasks: [] });
@ -129,6 +129,8 @@ export async function GET() {
}
const projectsData = await projectsResponse.json();
console.log('Projects response:', JSON.stringify(projectsData, null, 2));
const projectsMap = new Map(
projectsData.result.map((project: any) => [project.id, project.name])
);
@ -137,13 +139,18 @@ export async function GET() {
const tasks: Task[] = [];
Object.entries(data.result).forEach(([projectId, statusGroups]) => {
const projectName = projectsMap.get(Number(projectId)) || `Project ${projectId}`;
console.log(`Processing project ${projectId} (${projectName}):`, JSON.stringify(statusGroups, null, 2));
if (typeof statusGroups === 'object' && statusGroups !== null) {
// Iterate through each status group
Object.entries(statusGroups).forEach(([statusType, statusLabels]) => {
console.log(` Status type ${statusType}:`, JSON.stringify(statusLabels, null, 2));
if (typeof statusLabels === 'object' && statusLabels !== null) {
// Each status label in the group
Object.values(statusLabels).forEach((label: any) => {
console.log(` Processing label:`, JSON.stringify(label, null, 2));
const headline = String(label.name || label.title || 'Untitled');
tasks.push({
id: label.id?.toString() || `${projectId}-${statusType}`,
@ -160,6 +167,8 @@ export async function GET() {
}
});
console.log('Transformed tasks:', JSON.stringify(tasks, null, 2));
// Sort tasks by status type
const statusOrder: Record<string, number> = {
'new': 1,