From 5b7532ee599e2590601156819845bc3548200bb5 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 24 Jan 2026 09:53:45 -0500 Subject: [PATCH] fix: prevent incorrect soft deletes of billing items CRITICAL BUG FIX: Billing items were being incorrectly soft-deleted during full sync because BILLING_ITEMS was missing from the hasDateFilter check. The Issue: - Billing items have a date filter (itemDate >= now - yearsBack) - Full sync with 90-day range fetched only recent billing items - Soft delete logic saw 89,714 older items not in fetched set - Incorrectly marked them as deleted (outside sync window) The Fix: - Added EntityType.BILLING_ITEMS to hasDateFilter check - Now billing items skip soft deletes (like tickets, tasks, time entries) - Prevents deletion of records outside the sync date range Recovery: - Restored all 89,714 incorrectly deleted billing items - UPDATE billing_items SET is_deleted = false WHERE is_deleted = true This is the same pattern used for tickets, tasks, and time entries which also have date filters and skip soft deletes. --- lib/services/entity-sync.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/services/entity-sync.ts b/lib/services/entity-sync.ts index ff6d274..a3c7129 100644 --- a/lib/services/entity-sync.ts +++ b/lib/services/entity-sync.ts @@ -350,6 +350,7 @@ export class EntitySyncService { const hasDateFilter = entity === EntityType.TICKETS || entity === EntityType.TASKS || entity === EntityType.TIME_ENTRIES || + entity === EntityType.BILLING_ITEMS || entity === EntityType.PROJECTS || entity === EntityType.CONTRACTS;