duties widget correction 4

This commit is contained in:
Alma 2025-04-13 19:00:36 +02:00
parent 1e01d2e356
commit fba4b1754b
2 changed files with 15 additions and 4 deletions

View File

@ -152,19 +152,28 @@ export async function GET(request: NextRequest) {
const tasks = data.result
.filter((task: any) => {
// Skip all completed tasks (status 5), whether they are main tasks or subtasks
// Skip all completed tasks (status 5)
if (task.status === 5) {
console.log(`Filtering out completed task ${task.id} (type: ${task.type || 'main'})`);
return false;
}
// For subtasks, check if parent task is completed
if (task.type === 'subtask' && task.dependingTicketId) {
const parentTask = data.result.find((t: any) => t.id === task.dependingTicketId);
if (parentTask && parentTask.status === 5) {
console.log(`Filtering out subtask ${task.id} because parent task ${task.dependingTicketId} is completed`);
return false;
}
}
// Convert both to strings for comparison to handle any type mismatches
const taskEditorId = String(task.editorId).trim();
const currentUserId = String(userId).trim();
// Only show tasks where the user is the editor
const isUserEditor = taskEditorId === currentUserId;
console.log(`Task ${task.id}: status=${task.status}, type=${task.type || 'main'}, isUserEditor=${isUserEditor}`);
console.log(`Task ${task.id}: status=${task.status}, type=${task.type || 'main'}, parentId=${task.dependingTicketId || 'none'}, isUserEditor=${isUserEditor}`);
return isUserEditor;
})
.map((task: any) => ({
@ -181,7 +190,8 @@ export async function GET(request: NextRequest) {
editorId: task.editorId,
editorFirstname: task.editorFirstname,
editorLastname: task.editorLastname,
type: task.type || null // Added type field to identify subtasks
type: task.type || null, // Added type field to identify subtasks
dependingTicketId: task.dependingTicketId || null // Added parent task reference
}));
console.log(`Found ${tasks.length} tasks assigned to user ${userId}`);

View File

@ -23,6 +23,7 @@ interface Task {
editTo?: string;
editFrom?: string;
type?: string;
dependingTicketId?: number | null;
}
interface ProjectSummary {
@ -110,7 +111,7 @@ export function Duties() {
.filter((task: Task) => {
const isNotDone = task.status !== 5;
// Log task details for debugging
console.log(`Task ${task.id}: status=${task.status}, type=${task.type || 'main'}, dateToFinish=${task.dateToFinish}, isNotDone=${isNotDone}`);
console.log(`Task ${task.id}: status=${task.status}, type=${task.type || 'main'}, parentId=${task.dependingTicketId || 'none'}, dateToFinish=${task.dateToFinish}, isNotDone=${isNotDone}`);
return isNotDone;
})
.sort((a: Task, b: Task) => {