working leantime widget 122
This commit is contained in:
parent
301d708263
commit
1a771c1c3a
@ -8,7 +8,7 @@ interface Task {
|
||||
projectName: string;
|
||||
projectId: number;
|
||||
status: number;
|
||||
dueDate: string | null;
|
||||
dateToFinish: string | null;
|
||||
milestone: string | null;
|
||||
details: string | null;
|
||||
createdOn: string;
|
||||
@ -152,14 +152,6 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
const tasks = data.result
|
||||
.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
|
||||
});
|
||||
|
||||
// Skip completed tasks (status 5)
|
||||
if (task.status === 5) {
|
||||
return false;
|
||||
@ -169,16 +161,8 @@ export async function GET(request: NextRequest) {
|
||||
const taskEditorId = String(task.editorId).trim();
|
||||
const currentUserId = String(userId).trim();
|
||||
|
||||
// Show tasks where:
|
||||
// 1. The user is the editor
|
||||
// 2. The task is unassigned (empty editorId)
|
||||
// 3. The user is in the assignedTo array
|
||||
// 4. The task's userId matches the current user
|
||||
return taskEditorId === currentUserId ||
|
||||
taskEditorId === '' ||
|
||||
task.userId === userId ||
|
||||
(Array.isArray(task.assignedTo) &&
|
||||
task.assignedTo.some((id: any) => String(id).trim() === currentUserId));
|
||||
// Show tasks where the user is the editor or the task is unassigned
|
||||
return taskEditorId === currentUserId || taskEditorId === '';
|
||||
})
|
||||
.map((task: any) => ({
|
||||
id: task.id.toString(),
|
||||
@ -187,7 +171,6 @@ export async function GET(request: NextRequest) {
|
||||
projectId: task.projectId,
|
||||
status: task.status,
|
||||
dateToFinish: task.dateToFinish || null,
|
||||
date: task.date || null,
|
||||
milestone: task.type || null,
|
||||
details: task.description || null,
|
||||
createdOn: task.dateCreated,
|
||||
@ -198,7 +181,7 @@ export async function GET(request: NextRequest) {
|
||||
}));
|
||||
|
||||
console.log(`Found ${tasks.length} tasks assigned to user ${userId}`);
|
||||
return NextResponse.json({ tasks });
|
||||
return NextResponse.json(tasks);
|
||||
} catch (error) {
|
||||
console.error('Error in tasks route:', error);
|
||||
return NextResponse.json(
|
||||
|
||||
@ -81,16 +81,9 @@ export function Flow() {
|
||||
};
|
||||
|
||||
const getValidDate = (task: Task): string | null => {
|
||||
// First check dateToFinish
|
||||
if (task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00') {
|
||||
return task.dateToFinish;
|
||||
}
|
||||
|
||||
// Then check date
|
||||
if (task.date && task.date !== '0000-00-00 00:00:00') {
|
||||
return task.date;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
@ -98,16 +91,19 @@ export function Flow() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await fetch('/api/leantime/tasks');
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch tasks');
|
||||
}
|
||||
const tasks = await response.json();
|
||||
|
||||
if (!Array.isArray(data)) {
|
||||
console.warn('No tasks found in response', data as unknown);
|
||||
if (!Array.isArray(tasks)) {
|
||||
console.warn('No tasks found in response', tasks as unknown);
|
||||
setTasks([]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Filter out completed tasks (status 3) and sort by date
|
||||
const sortedTasks = data
|
||||
// Filter out completed tasks (status 3) and sort by dateToFinish
|
||||
const sortedTasks = tasks
|
||||
.filter((task: Task) => task.status !== 3)
|
||||
.sort((a: Task, b: Task) => {
|
||||
const dateA = getValidDate(a);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user