fix: sync preserves manually edited items (status edited/pending)

This commit is contained in:
Christian Vidal Wolf
2026-04-23 16:10:01 +02:00
parent c2b229e899
commit 605b93c445
+11 -6
View File
@@ -40,18 +40,23 @@ export default async function handler(req, res) {
} }
const articleNoIdx = 0; const articleNoIdx = 0;
// Fetch IDs of products that have been manually edited so we don't overwrite them // Fetch IDs of ALL products that have manual edits so we don't overwrite them
const { data: protectedProducts } = await supabase const { data: existingProducts } = await supabase
.from('products') .from('products')
.select('product_id') .select('product_id, status');
.or('status.eq.edited,status.eq.pending');
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 = []; const productsToUpsert = [];
for (const row of rows) { for (const row of rows) {
const productId = String(row[articleNoIdx]); 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({ productsToUpsert.push({
product_id: productId, product_id: productId,
data: row, data: row,