correction finition widget done

This commit is contained in:
alma 2026-01-19 22:10:25 +01:00
parent eccd254372
commit c402dc6a0c

View File

@ -332,8 +332,12 @@ async function fetchTwentyTasks(userId?: string): Promise<TwentyTask[]> {
const tasks: TwentyTask[] = filteredByAssignee const tasks: TwentyTask[] = filteredByAssignee
.filter((task: TwentyTask) => { .filter((task: TwentyTask) => {
// Filter: only overdue tasks (dueAt < today) and not completed // Filter: only overdue tasks (dueAt < today) and not completed
if (task.status === 'Done') { // Check if task is done (case-insensitive to handle "Done", "done", "DONE", etc.)
return false; if (task.status) {
const status = task.status.trim().toLowerCase();
if (status === 'done') {
return false;
}
} }
if (!task.dueAt) { if (!task.dueAt) {
@ -366,6 +370,7 @@ async function fetchTwentyTasks(userId?: string): Promise<TwentyTask[]> {
logger.debug('[TWENTY_CRM_TASKS] Tasks after filtering', { logger.debug('[TWENTY_CRM_TASKS] Tasks after filtering', {
count: tasks.length, count: tasks.length,
filteredOutDone: filteredByAssignee.length - tasks.length,
}); });
logger.debug('[TWENTY_CRM_TASKS] Successfully fetched tasks from Twenty CRM', { logger.debug('[TWENTY_CRM_TASKS] Successfully fetched tasks from Twenty CRM', {
@ -423,14 +428,18 @@ export async function GET(request: NextRequest) {
const tasks = await fetchTwentyTasks(twentyCrmUserId); const tasks = await fetchTwentyTasks(twentyCrmUserId);
// Transform to match Leantime task format for consistency // Transform to match Leantime task format for consistency
const transformedTasks = tasks.map((task) => ({ const transformedTasks = tasks.map((task) => {
id: `twenty-${task.id}`, // Prefix to avoid conflicts with Leantime IDs // Check if task is done (case-insensitive)
headline: task.title, const isDone = task.status ? task.status.trim().toLowerCase() === 'done' : false;
description: (task as any)._bodyText || null, // Use extracted body text
dateToFinish: task.dueAt || null, // For Twenty CRM, dueAt is used as the notification time return {
projectName: 'Médiation', id: `twenty-${task.id}`, // Prefix to avoid conflicts with Leantime IDs
projectId: 0, headline: task.title,
status: task.status === 'Done' ? 5 : 1, // 5 = Done, 1 = New (or other status) description: (task as any)._bodyText || null, // Use extracted body text
dateToFinish: task.dueAt || null, // For Twenty CRM, dueAt is used as the notification time
projectName: 'Médiation',
projectId: 0,
status: isDone ? 5 : 1, // 5 = Done, 1 = New (or other status)
editorId: task.assigneeId || null, editorId: task.assigneeId || null,
editorFirstname: task.assignee?.name?.firstName || null, editorFirstname: task.assignee?.name?.firstName || null,
editorLastname: task.assignee?.name?.lastName || null, editorLastname: task.assignee?.name?.lastName || null,
@ -443,7 +452,8 @@ export async function GET(request: NextRequest) {
dependingTicketId: null, dependingTicketId: null,
source: 'twenty-crm', // Add source identifier source: 'twenty-crm', // Add source identifier
url: process.env.TWENTY_CRM_URL ? `${process.env.TWENTY_CRM_URL}/object/task/${task.id}` : null, url: process.env.TWENTY_CRM_URL ? `${process.env.TWENTY_CRM_URL}/object/task/${task.id}` : null,
})); };
});
logger.debug('[TWENTY_CRM_TASKS] Transformed tasks', { logger.debug('[TWENTY_CRM_TASKS] Transformed tasks', {
count: transformedTasks.length, count: transformedTasks.length,