mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 11:35:24 +02:00
fix: sync preserves manually edited items (status edited/pending)
This commit is contained in:
+11
-6
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user