diff --git a/lib/utils/sync-helpers.ts b/lib/utils/sync-helpers.ts index d259d1e..6af2ece 100644 --- a/lib/utils/sync-helpers.ts +++ b/lib/utils/sync-helpers.ts @@ -162,7 +162,7 @@ export function getLastModifiedField(entity: EntityType): string { [EntityType.CONTRACT_SERVICES]: 'lastModifiedDate', [EntityType.AUTOTASK_SERVICES]: 'lastModifiedDate', [EntityType.BILLING_ITEMS]: 'itemDate', - [EntityType.TIME_ENTRIES]: 'dateWorked', + [EntityType.TIME_ENTRIES]: 'lastModifiedDateTime', [EntityType.TICKET_NOTES]: 'lastActivityDate', [EntityType.STATUSES]: 'lastModifiedDate', [EntityType.ISSUE_TYPES]: 'lastModifiedDate', @@ -360,18 +360,20 @@ export function buildProjectsFilter(): Array<{ field: string; op: string; value: * @returns Query filter array for time entries */ export function buildTimeEntriesFilter(yearsBack: number = 2): Array<{ field: string; op: string; value: any }> { - // TimeEntries API requires a filter. Use dateWorked to limit the range - // Calculate date from X years ago + // TimeEntries API requires a filter. Use lastModifiedDateTime so that edits + // to existing entries (e.g. hours changed, notes updated) are picked up even + // if the dateWorked is in the past or future. + // We still bound it by yearsBack to avoid a full scan on first load. const cutoffDate = new Date(); const millisecondsPerYear = 365.25 * 24 * 60 * 60 * 1000; const millisecondsBack = yearsBack * millisecondsPerYear; cutoffDate.setTime(cutoffDate.getTime() - millisecondsBack); - console.log(`TimeEntries filter: dateWorked >= ${cutoffDate.toISOString()} (${yearsBack} years back)`); + console.log(`TimeEntries filter: lastModifiedDateTime >= ${cutoffDate.toISOString()} (${yearsBack} years back)`); return [ { - field: 'dateWorked', + field: 'lastModifiedDateTime', op: 'gte', value: cutoffDate.toISOString(), },