mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 14: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> {
|
export async function saveRowToSupabase(articleNo: string, rowData: ExcelRow): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${SUPABASE_URL}/rest/v1/products?product_id=eq.${encodeURIComponent(articleNo)}`,
|
`${SUPABASE_URL}/rest/v1/products`,
|
||||||
{
|
{
|
||||||
method: 'PATCH',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'apikey': SUPABASE_KEY,
|
'apikey': SUPABASE_KEY,
|
||||||
'Authorization': `Bearer ${SUPABASE_KEY}`,
|
'Authorization': `Bearer ${SUPABASE_KEY}`,
|
||||||
'Prefer': 'return=minimal'
|
'Prefer': 'resolution=merge-duplicates'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
product_id: articleNo,
|
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) {
|
} catch (error) {
|
||||||
console.error('Error saving to Supabase:', error);
|
console.error('Error saving to Supabase:', error);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user