Widget Devoir Finition
This commit is contained in:
parent
6886b258ba
commit
4e0cb62d0b
@ -99,12 +99,40 @@ export async function GET(request: NextRequest) {
|
||||
// Try to get data from cache if not forcing refresh
|
||||
if (!forceRefresh) {
|
||||
const cachedTasks = await getCachedTasksData(session.user.id);
|
||||
if (cachedTasks) {
|
||||
if (cachedTasks && Array.isArray(cachedTasks)) {
|
||||
// Filter out done tasks from cache as well (in case cache contains old data)
|
||||
const filteredCachedTasks = cachedTasks.filter((task: any) => {
|
||||
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') {
|
||||
logger.debug('[LEANTIME_TASKS] Filtering out done task from cache', {
|
||||
id: task.id,
|
||||
headline: task.headline,
|
||||
status: taskStatus,
|
||||
statusNum,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (filteredCachedTasks.length !== cachedTasks.length) {
|
||||
logger.debug('[LEANTIME_TASKS] Filtered done tasks from cache', {
|
||||
before: cachedTasks.length,
|
||||
after: filteredCachedTasks.length,
|
||||
removed: cachedTasks.length - filteredCachedTasks.length,
|
||||
});
|
||||
// Update cache with filtered tasks
|
||||
await cacheTasksData(session.user.id, filteredCachedTasks);
|
||||
}
|
||||
|
||||
logger.debug('[LEANTIME_TASKS] Using cached tasks data', {
|
||||
emailHash: Buffer.from(session.user.email.toLowerCase()).toString('base64').slice(0, 12),
|
||||
taskCount: Array.isArray(cachedTasks) ? cachedTasks.length : undefined,
|
||||
taskCount: filteredCachedTasks.length,
|
||||
});
|
||||
return NextResponse.json(cachedTasks);
|
||||
return NextResponse.json(filteredCachedTasks);
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,8 +193,19 @@ export async function GET(request: NextRequest) {
|
||||
const tasks = data.result
|
||||
.filter((task: any) => {
|
||||
// Filter out any task (main or subtask) that has status Done (5)
|
||||
if (task.status === 5) {
|
||||
return false;
|
||||
// Handle both number and string formats, and check for null/undefined
|
||||
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') {
|
||||
logger.debug('[LEANTIME_TASKS] Filtering out done task', {
|
||||
id: task.id,
|
||||
headline: task.headline,
|
||||
status: taskStatus,
|
||||
statusNum,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert both to strings for comparison to handle any type mismatches
|
||||
|
||||
@ -118,6 +118,19 @@ export function Duties() {
|
||||
const leantimeData = await leantimeResponse.value.json();
|
||||
if (Array.isArray(leantimeData)) {
|
||||
leantimeTasks = leantimeData;
|
||||
// Log tasks with status 5 to debug
|
||||
const doneTasks = leantimeData.filter((t: Task) => {
|
||||
const status = typeof t.status === 'string' ? parseInt(t.status, 10) : t.status;
|
||||
return status === 5 || t.status === '5' || t.status === 'Done' || t.status === 'done' || t.status === 'DONE';
|
||||
});
|
||||
if (doneTasks.length > 0) {
|
||||
console.warn('[Devoirs Widget] ⚠️ Received done tasks from Leantime API:', doneTasks.map((t: Task) => ({
|
||||
id: t.id,
|
||||
headline: t.headline,
|
||||
status: t.status,
|
||||
statusType: typeof t.status,
|
||||
})));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.warn('Failed to fetch Leantime tasks:', leantimeResponse);
|
||||
@ -141,6 +154,7 @@ export function Duties() {
|
||||
leantime: leantimeTasks.length,
|
||||
twentyCrm: twentyCrmTasks.length,
|
||||
total: allTasks.length,
|
||||
leantimeStatuses: leantimeTasks.map((t: Task) => ({ id: t.id, status: t.status, statusType: typeof t.status })),
|
||||
});
|
||||
|
||||
if (allTasks.length === 0) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user