working leantime widget 67
This commit is contained in:
parent
5a59f124e2
commit
fbeb73ec44
@ -142,23 +142,27 @@ export async function GET(request: NextRequest) {
|
||||
throw new Error('Invalid response format from Leantime');
|
||||
}
|
||||
|
||||
console.log('Leantime tasks response:', {
|
||||
success: true,
|
||||
taskCount: data.result?.length || 0
|
||||
});
|
||||
|
||||
if (!data.result || !Array.isArray(data.result)) {
|
||||
console.error('Invalid response format from Leantime tasks API');
|
||||
throw new Error('Invalid response format from Leantime');
|
||||
}
|
||||
|
||||
// Log the first task to see its complete structure
|
||||
console.log('Sample task structure:', JSON.stringify(data.result[0], null, 2));
|
||||
|
||||
const tasks = data.result
|
||||
.filter((task: any) =>
|
||||
// Include tasks where the user is the editor
|
||||
task.editorId === userId.toString() ||
|
||||
// Or tasks explicitly assigned to the user (if assignedTo exists)
|
||||
(Array.isArray(task.assignedTo) && task.assignedTo.includes(userId))
|
||||
)
|
||||
.filter((task: any) => {
|
||||
// Log task assignment details
|
||||
console.log(`Task ${task.id} - ${task.headline}:`, {
|
||||
editorId: task.editorId,
|
||||
userId: userId,
|
||||
assignedTo: task.assignedTo,
|
||||
status: task.status
|
||||
});
|
||||
|
||||
// Only include tasks where the current user is assigned
|
||||
return task.editorId === userId.toString();
|
||||
})
|
||||
.map((task: any) => ({
|
||||
id: task.id.toString(),
|
||||
headline: task.headline,
|
||||
@ -175,13 +179,7 @@ export async function GET(request: NextRequest) {
|
||||
editorLastname: task.editorLastname
|
||||
}));
|
||||
|
||||
// Sort tasks by creation date (oldest first)
|
||||
tasks.sort((a: Task, b: Task) => {
|
||||
const dateA = new Date(a.createdOn).getTime();
|
||||
const dateB = new Date(b.createdOn).getTime();
|
||||
return dateA - dateB;
|
||||
});
|
||||
|
||||
console.log(`Found ${tasks.length} tasks assigned to user ${userId}`);
|
||||
return NextResponse.json({ tasks });
|
||||
} catch (error) {
|
||||
console.error('Error in tasks route:', error);
|
||||
|
||||
@ -9,19 +9,12 @@ interface Task {
|
||||
id: number;
|
||||
headline: string;
|
||||
description: string;
|
||||
date: string;
|
||||
dateToFinish: string;
|
||||
projectId: number;
|
||||
projectName: string;
|
||||
type: string;
|
||||
status: number;
|
||||
dateToFinish: string;
|
||||
editorId: string;
|
||||
editorFirstname: string | null;
|
||||
editorLastname: string | null;
|
||||
authorFirstname: string;
|
||||
authorLastname: string;
|
||||
milestoneHeadline: string | null;
|
||||
tags: string;
|
||||
}
|
||||
|
||||
interface ProjectSummary {
|
||||
@ -91,13 +84,15 @@ export function Flow() {
|
||||
if (!response.ok) throw new Error('Failed to fetch tasks');
|
||||
|
||||
const data = await response.json();
|
||||
console.log('Tasks API response:', data);
|
||||
|
||||
if (!data.tasks || !Array.isArray(data.tasks)) {
|
||||
console.warn('No tasks found in response:', data);
|
||||
setTasks([]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Sort tasks by date (oldest first)
|
||||
// Sort tasks by status and date
|
||||
const sortedTasks = data.tasks
|
||||
.filter((task: Task) =>
|
||||
task.headline &&
|
||||
@ -109,11 +104,17 @@ export function Flow() {
|
||||
if (a.status !== b.status) {
|
||||
return a.status - b.status;
|
||||
}
|
||||
// Then sort by due date
|
||||
return getDateToSort(a) - getDateToSort(b);
|
||||
// Then sort by due date if available
|
||||
const dateA = a.dateToFinish && a.dateToFinish !== '0000-00-00 00:00:00'
|
||||
? new Date(a.dateToFinish).getTime()
|
||||
: Date.now();
|
||||
const dateB = b.dateToFinish && b.dateToFinish !== '0000-00-00 00:00:00'
|
||||
? new Date(b.dateToFinish).getTime()
|
||||
: Date.now();
|
||||
return dateA - dateB;
|
||||
});
|
||||
|
||||
// Limit to 6 tasks
|
||||
console.log('Filtered and sorted tasks:', sortedTasks);
|
||||
setTasks(sortedTasks.slice(0, 6));
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user