fix: merge history data into rows when products table is empty

This commit is contained in:
Christian Vidal Wolf
2026-04-23 19:07:38 +02:00
parent ee94926d04
commit c1e3960a20
2 changed files with 44 additions and 9 deletions
+29
View File
@@ -194,6 +194,35 @@ export async function getHistory(): Promise<HistoryEntry[]> {
}
}
export async function getHistoryDataForMerge(): Promise<Record<string, ExcelRow>> {
try {
const response = await safeFetch(
`${SUPABASE_URL}/rest/v1/products_history?select=product_id,new_data&order=changed_at.desc`,
{ cache: 'no-store' }
);
if (!response.ok) {
console.error('[getHistoryDataForMerge] Error:', response.status);
return {};
}
const entries: Array<{ product_id: string; new_data: ExcelRow }> = await response.json();
const result: Record<string, ExcelRow> = {};
const seen = new Set<string>();
for (const entry of entries) {
if (seen.has(entry.product_id)) continue;
seen.add(entry.product_id);
if (entry.new_data && entry.new_data.length > 0) {
result[entry.product_id] = entry.new_data;
}
}
return result;
} catch (error: any) {
console.error('[getHistoryDataForMerge] Exception:', error.message);
return {};
}
}
export async function deleteHistoryEntry(id: string): Promise<boolean> {
try {
const response = await safeFetch(