Widget Devoir Finition
This commit is contained in:
parent
8f9c01ebea
commit
245c9c97ee
@ -184,9 +184,23 @@ export async function GET(request: NextRequest) {
|
||||
throw new Error('Invalid response format from Leantime');
|
||||
}
|
||||
|
||||
// Log only the number of tasks and their IDs
|
||||
// Log detailed status information before filtering
|
||||
const statusBreakdownBefore = data.result.reduce((acc: any, task: any) => {
|
||||
const status = task.status;
|
||||
const statusKey = String(status);
|
||||
if (!acc[statusKey]) {
|
||||
acc[statusKey] = { count: 0, type: typeof status, sample: [] };
|
||||
}
|
||||
acc[statusKey].count++;
|
||||
if (acc[statusKey].sample.length < 3) {
|
||||
acc[statusKey].sample.push({ id: task.id, headline: task.headline });
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
logger.debug('[LEANTIME_TASKS] Received tasks summary', {
|
||||
count: data.result.length,
|
||||
statusBreakdown: statusBreakdownBefore,
|
||||
idsSample: data.result.slice(0, 20).map((task: any) => task.id),
|
||||
});
|
||||
|
||||
@ -197,12 +211,17 @@ export async function GET(request: NextRequest) {
|
||||
const taskStatus = task.status;
|
||||
if (taskStatus !== null && taskStatus !== undefined) {
|
||||
const statusNum = typeof taskStatus === 'string' ? parseInt(taskStatus, 10) : taskStatus;
|
||||
if (statusNum === 5 || taskStatus === '5' || taskStatus === 'Done' || taskStatus === 'done' || taskStatus === 'DONE') {
|
||||
const statusStr = typeof taskStatus === 'string' ? taskStatus.trim().toLowerCase() : String(taskStatus).trim().toLowerCase();
|
||||
const isDone = statusNum === 5 || statusStr === '5' || statusStr === 'done';
|
||||
|
||||
if (isDone) {
|
||||
logger.debug('[LEANTIME_TASKS] Filtering out done task', {
|
||||
id: task.id,
|
||||
headline: task.headline,
|
||||
status: taskStatus,
|
||||
statusType: typeof taskStatus,
|
||||
statusNum,
|
||||
statusStr,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
@ -234,9 +253,27 @@ export async function GET(request: NextRequest) {
|
||||
dependingTicketId: task.dependingTicketId || null // Added parent task reference
|
||||
}));
|
||||
|
||||
// Log detailed status information for debugging
|
||||
const statusBreakdown = tasks.reduce((acc: any, task: any) => {
|
||||
const status = task.status;
|
||||
const statusKey = String(status);
|
||||
if (!acc[statusKey]) {
|
||||
acc[statusKey] = 0;
|
||||
}
|
||||
acc[statusKey]++;
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
logger.debug('[LEANTIME_TASKS] Filtered tasks for user', {
|
||||
userId,
|
||||
count: tasks.length,
|
||||
statusBreakdown,
|
||||
sampleTasks: tasks.slice(0, 5).map((t: any) => ({
|
||||
id: t.id,
|
||||
headline: t.headline,
|
||||
status: t.status,
|
||||
statusType: typeof t.status,
|
||||
})),
|
||||
});
|
||||
|
||||
// Cache the results
|
||||
|
||||
@ -153,11 +153,35 @@ export function Duties() {
|
||||
// Combine tasks from both sources
|
||||
const allTasks = [...leantimeTasks, ...twentyCrmTasks];
|
||||
|
||||
// Log detailed status information
|
||||
const leantimeStatusDetails = leantimeTasks.map((t: Task) => {
|
||||
const rawStatus = (t as any).status;
|
||||
const statusNum = typeof rawStatus === 'string' ? parseInt(rawStatus, 10) : rawStatus;
|
||||
const isDone = statusNum === 5 || (typeof rawStatus === 'string' && rawStatus.toLowerCase() === 'done');
|
||||
return {
|
||||
id: t.id,
|
||||
headline: t.headline,
|
||||
status: rawStatus,
|
||||
statusType: typeof rawStatus,
|
||||
statusNum,
|
||||
isDone,
|
||||
};
|
||||
});
|
||||
|
||||
const doneTasksCount = leantimeStatusDetails.filter(t => t.isDone).length;
|
||||
if (doneTasksCount > 0) {
|
||||
console.warn('[Devoirs Widget] ⚠️ Found done tasks in Leantime data:', {
|
||||
total: leantimeTasks.length,
|
||||
doneCount: doneTasksCount,
|
||||
doneTasks: leantimeStatusDetails.filter(t => t.isDone),
|
||||
});
|
||||
}
|
||||
|
||||
console.log('Combined tasks:', {
|
||||
leantime: leantimeTasks.length,
|
||||
twentyCrm: twentyCrmTasks.length,
|
||||
total: allTasks.length,
|
||||
leantimeStatuses: leantimeTasks.map((t: Task) => ({ id: t.id, status: t.status, statusType: typeof t.status })),
|
||||
leantimeStatuses: leantimeStatusDetails,
|
||||
});
|
||||
|
||||
if (allTasks.length === 0) {
|
||||
@ -213,6 +237,18 @@ export function Duties() {
|
||||
return isOverdueOrDueToday;
|
||||
});
|
||||
|
||||
// Log filtered results
|
||||
console.log('[Devoirs Widget] Filtering results:', {
|
||||
before: allTasks.length,
|
||||
after: filteredTasks.length,
|
||||
filteredOut: allTasks.length - filteredTasks.length,
|
||||
filteredTasksStatuses: filteredTasks.map((t: Task) => ({
|
||||
id: t.id,
|
||||
headline: t.headline,
|
||||
status: (t as any).status,
|
||||
})),
|
||||
});
|
||||
|
||||
// Sort by dateToFinish (oldest first)
|
||||
const sortedTasks = filteredTasks
|
||||
.sort((a: Task, b: Task) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user