diff --git a/src/routes/settings.import.tsx b/src/routes/settings.import.tsx index 2a19b21..91642b3 100644 --- a/src/routes/settings.import.tsx +++ b/src/routes/settings.import.tsx @@ -746,10 +746,10 @@ function ImportPage() { const withConflict = chunk.filter((r) => r[cfg.conflict]); const withoutConflict = chunk.filter((r) => !r[cfg.conflict]); - if (cfg.table === "time_entries" && withConflict.length > 0) { + if ((cfg.table === "time_entries" || cfg.table === "invoices") && withConflict.length > 0) { const externalIds = withConflict.map((r) => String(r[cfg.conflict])); const { data: existing, error: lookupError } = await supabase - .from("time_entries") + .from(cfg.table as any) .select("id, external_id") .in("external_id", externalIds); @@ -757,7 +757,9 @@ function ImportPage() { errors.push(`Batch ${i / chunkSize + 1} (lookup): ${lookupError.message}`); } else { const existingByExternalId = new Map( - (existing ?? []).map((entry: { id: string; external_id: string | null }) => [entry.external_id, entry.id]), + ((existing ?? []) as unknown as Array<{ id: string; external_id: string | null }>).map( + (entry) => [entry.external_id, entry.id] as [string | null, string], + ), ); const toUpdate: Array = withConflict .filter((r) => existingByExternalId.has(String(r.external_id))) @@ -768,7 +770,7 @@ function ImportPage() { const updateResults = await Promise.all( toUpdate.map(async (entry) => { const { id, ...payload } = entry; - return supabase.from("time_entries").update(payload as any).eq("id", id).select("*").single(); + return supabase.from(cfg.table as any).update(payload as any).eq("id", id).select("*").single(); }), ); for (const result of updateResults) { @@ -776,21 +778,21 @@ function ImportPage() { errors.push(`Batch ${i / chunkSize + 1} (update): ${result.error.message}`); } else if (result.data) { inserted += 1; - inserted_rows.push(result.data); + inserted_rows.push(result.data as Row); } } } if (toInsert.length > 0) { const { data, error } = await supabase - .from("time_entries") + .from(cfg.table as any) .insert(toInsert as any) .select("*"); if (error) { errors.push(`Batch ${i / chunkSize + 1} (insert): ${error.message}`); } else if (data) { inserted += data.length; - inserted_rows.push(...data); + inserted_rows.push(...(data as Row[])); } } }