mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 14:05:25 +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;
|
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,
|
||||||
|
|||||||
Reference in New Issue
Block a user