widget leantime refactor
This commit is contained in:
parent
ad047327c6
commit
26d453107d
@ -42,20 +42,11 @@ async function fetchTwentyTasks(): Promise<TwentyTask[]> {
|
|||||||
const todayISO = today.toISOString();
|
const todayISO = today.toISOString();
|
||||||
|
|
||||||
// GraphQL query to fetch tasks from Twenty CRM
|
// GraphQL query to fetch tasks from Twenty CRM
|
||||||
// Based on error messages, using correct field names:
|
// Trying simpler query first - tasks may not accept filter/orderBy arguments
|
||||||
// - filter instead of where
|
// We'll filter client-side if needed
|
||||||
// - bodyV2 instead of body
|
|
||||||
// - status field instead of completedAt (need to check what status values mean)
|
|
||||||
// - name instead of firstName/lastName/email for WorkspaceMember
|
|
||||||
const query = `
|
const query = `
|
||||||
query GetOverdueTasks {
|
query GetTasks {
|
||||||
tasks(
|
tasks {
|
||||||
filter: {
|
|
||||||
status: { neq: Done }
|
|
||||||
dueAt: { lt: "${todayISO}" }
|
|
||||||
}
|
|
||||||
orderBy: { dueAt: AscNullsLast }
|
|
||||||
) {
|
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
id
|
id
|
||||||
@ -148,36 +139,62 @@ async function fetchTwentyTasks(): Promise<TwentyTask[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Transform Twenty CRM tasks to match our Task interface
|
// Transform Twenty CRM tasks to match our Task interface
|
||||||
const tasks: TwentyTask[] = activitiesData.map((edge: any) => {
|
// Filter client-side for overdue tasks (dueAt < today) and not completed (status !== 'Done')
|
||||||
const node = edge.node || edge; // Handle both edge.node and direct node
|
const tasks: TwentyTask[] = activitiesData
|
||||||
|
.map((edge: any) => {
|
||||||
// Extract text from bodyV2 if it's a rich text object
|
const node = edge.node || edge; // Handle both edge.node and direct node
|
||||||
let bodyText = null;
|
|
||||||
if (node.bodyV2) {
|
// Extract text from bodyV2 if it's a rich text object
|
||||||
if (typeof node.bodyV2 === 'string') {
|
let bodyText = null;
|
||||||
bodyText = node.bodyV2;
|
if (node.bodyV2) {
|
||||||
} else if (node.bodyV2 && typeof node.bodyV2 === 'object') {
|
if (typeof node.bodyV2 === 'string') {
|
||||||
// Try to extract text from rich text structure
|
bodyText = node.bodyV2;
|
||||||
bodyText = JSON.stringify(node.bodyV2).substring(0, 200);
|
} else if (node.bodyV2 && typeof node.bodyV2 === 'object') {
|
||||||
|
// Try to extract text from rich text structure
|
||||||
|
bodyText = JSON.stringify(node.bodyV2).substring(0, 200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return {
|
||||||
return {
|
id: node.id,
|
||||||
id: node.id,
|
title: node.title || 'Untitled Task',
|
||||||
title: node.title || 'Untitled Task',
|
bodyV2: node.bodyV2 || null,
|
||||||
bodyV2: node.bodyV2 || null,
|
dueAt: node.dueAt || null,
|
||||||
dueAt: node.dueAt || null,
|
status: node.status || null,
|
||||||
status: node.status || null,
|
type: node.type || 'Task',
|
||||||
type: node.type || 'Task',
|
assigneeId: node.assigneeId || null,
|
||||||
assigneeId: node.assigneeId || null,
|
assignee: node.assignee ? {
|
||||||
assignee: node.assignee ? {
|
id: node.assignee.id,
|
||||||
id: node.assignee.id,
|
name: node.assignee.name || null,
|
||||||
name: node.assignee.name || null,
|
} : null,
|
||||||
} : null,
|
// Store extracted body text for easier access
|
||||||
// Store extracted body text for easier access
|
_bodyText: bodyText,
|
||||||
_bodyText: bodyText,
|
};
|
||||||
};
|
})
|
||||||
});
|
.filter((task: TwentyTask) => {
|
||||||
|
// Filter: only overdue tasks (dueAt < today) and not completed
|
||||||
|
if (task.status === 'Done') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!task.dueAt) {
|
||||||
|
return false; // Exclude tasks without due date
|
||||||
|
}
|
||||||
|
|
||||||
|
const taskDueDate = new Date(task.dueAt);
|
||||||
|
taskDueDate.setHours(0, 0, 0, 0);
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
return taskDueDate < today; // Only overdue tasks
|
||||||
|
})
|
||||||
|
.sort((a: TwentyTask, b: TwentyTask) => {
|
||||||
|
// Sort by dueAt (oldest first)
|
||||||
|
if (!a.dueAt || !b.dueAt) return 0;
|
||||||
|
const dateA = new Date(a.dueAt).getTime();
|
||||||
|
const dateB = new Date(b.dueAt).getTime();
|
||||||
|
return dateA - dateB;
|
||||||
|
});
|
||||||
|
|
||||||
logger.debug('[TWENTY_CRM_TASKS] Successfully fetched tasks from Twenty CRM', {
|
logger.debug('[TWENTY_CRM_TASKS] Successfully fetched tasks from Twenty CRM', {
|
||||||
count: tasks.length,
|
count: tasks.length,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user