mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 13:05:25 +02:00
fix: use POST with upsert instead of PATCH to handle new products
This commit is contained in:
+4
-4
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user