mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 12:25:23 +02:00
fix: protect products with history from being overwritten by Dropbox sync
Products that have entries in products_history were edited at some point. If their status was accidentally reset to 'excel', the sync would overwrite their data. Now also check products_history to build the protected set. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
80f86cb83e
commit
59e4bdeb92
+9
-2
@@ -44,14 +44,21 @@ export default async function handler(req, res) {
|
|||||||
const { data: existingProducts } = await supabase
|
const { data: existingProducts } = await supabase
|
||||||
.from('products')
|
.from('products')
|
||||||
.select('product_id, status');
|
.select('product_id, status');
|
||||||
|
|
||||||
// Only skip if status is 'edited' or 'pending' (manual edits)
|
// Protect products with status 'edited' or 'pending'
|
||||||
const manuallyEditedIds = new Set(
|
const manuallyEditedIds = new Set(
|
||||||
(existingProducts || [])
|
(existingProducts || [])
|
||||||
.filter(p => p.status === 'edited' || p.status === 'pending')
|
.filter(p => p.status === 'edited' || p.status === 'pending')
|
||||||
.map(p => p.product_id)
|
.map(p => p.product_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Also protect any product that has history entries — they were edited at some point.
|
||||||
|
// If their status was accidentally reset to 'excel', this restores protection.
|
||||||
|
const { data: historyProducts } = await supabase
|
||||||
|
.from('products_history')
|
||||||
|
.select('product_id');
|
||||||
|
(historyProducts || []).forEach(h => manuallyEditedIds.add(h.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]);
|
||||||
|
|||||||
Reference in New Issue
Block a user