fix: use POST with upsert instead of PATCH to handle new products

This commit is contained in:
Christian Vidal Wolf
2026-04-10 10:48:05 +02:00
parent 0139e1de20
commit 077e78513c
+4 -4
View File
@@ -36,14 +36,14 @@ export async function getAllSyncedRows(): Promise<Record<string, SyncedRow>> {
export async function saveRowToSupabase(articleNo: string, rowData: ExcelRow): Promise<boolean> {
try {
const response = await fetch(
`${SUPABASE_URL}/rest/v1/products?product_id=eq.${encodeURIComponent(articleNo)}`,
`${SUPABASE_URL}/rest/v1/products`,
{
method: 'PATCH',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'apikey': SUPABASE_KEY,
'Authorization': `Bearer ${SUPABASE_KEY}`,
'Prefer': 'return=minimal'
'Prefer': 'resolution=merge-duplicates'
},
body: JSON.stringify({
product_id: articleNo,
@@ -54,7 +54,7 @@ export async function saveRowToSupabase(articleNo: string, rowData: ExcelRow): P
}
);
return response.ok;
return response.ok || response.status === 201;
} catch (error) {
console.error('Error saving to Supabase:', error);
return false;