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
.filter((task: TwentyTask) => {
// Filter: only overdue tasks (dueAt < today) and not completed
if (task.status === 'Done') {
return false;
// Check if task is done (case-insensitive to handle "Done", "done", "DONE", etc.)
if (task.status) {
const status = task.status.trim().toLowerCase();
if (status === 'done') {
return false;
}
}
if (!task.dueAt) {
@ -366,6 +370,7 @@ async function fetchTwentyTasks(userId?: string): Promise<TwentyTask[]> {
logger.debug('[TWENTY_CRM_TASKS] Tasks after filtering', {
count: tasks.length,
filteredOutDone: filteredByAssignee.length - tasks.length,
});
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);
// Transform to match Leantime task format for consistency
const transformedTasks = tasks.map((task) => ({
id: `twenty-${task.id}`, // Prefix to avoid conflicts with Leantime IDs
headline: task.title,
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: task.status === 'Done' ? 5 : 1, // 5 = Done, 1 = New (or other status)
const transformedTasks = tasks.map((task) => {
// Check if task is done (case-insensitive)
const isDone = task.status ? task.status.trim().toLowerCase() === 'done' : false;
return {
id: `twenty-${task.id}`, // Prefix to avoid conflicts with Leantime IDs
headline: task.title,
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,
editorFirstname: task.assignee?.name?.firstName || null,
editorLastname: task.assignee?.name?.lastName || null,
@ -443,7 +452,8 @@ export async function GET(request: NextRequest) {
dependingTicketId: null,
source: 'twenty-crm', // Add source identifier
url: process.env.TWENTY_CRM_URL ? `${process.env.TWENTY_CRM_URL}/object/task/${task.id}` : null,
}));
};
});
logger.debug('[TWENTY_CRM_TASKS] Transformed tasks', {
count: transformedTasks.length,