From 605b93c445762cd52627f8eaef95a08072507a38 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Thu, 23 Apr 2026 16:10:01 +0200 Subject: [PATCH] fix: sync preserves manually edited items (status edited/pending) --- api/dropbox-sync.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/api/dropbox-sync.js b/api/dropbox-sync.js index 79562e1..eccf8bb 100644 --- a/api/dropbox-sync.js +++ b/api/dropbox-sync.js @@ -40,18 +40,23 @@ export default async function handler(req, res) { } const articleNoIdx = 0; - // Fetch IDs of products that have been manually edited so we don't overwrite them - const { data: protectedProducts } = await supabase + // Fetch IDs of ALL products that have manual edits so we don't overwrite them + const { data: existingProducts } = await supabase .from('products') - .select('product_id') - .or('status.eq.edited,status.eq.pending'); + .select('product_id, status'); - const protectedIds = new Set((protectedProducts || []).map(p => p.product_id)); + // Only skip if status is 'edited' or 'pending' (manual edits) + const manuallyEditedIds = new Set( + (existingProducts || []) + .filter(p => p.status === 'edited' || p.status === 'pending') + .map(p => p.product_id) + ); const productsToUpsert = []; for (const row of rows) { const productId = String(row[articleNoIdx]); - if (productId && productId.trim() !== '' && !protectedIds.has(productId)) { + // Only add if: new product OR existing but NOT manually edited + if (productId && productId.trim() !== '' && !manuallyEditedIds.has(productId)) { productsToUpsert.push({ product_id: productId, data: row,