Skipped missing clients in invoices

X-Lovable-Edit-ID: edt-997ec0cd-76c6-4d71-9bbf-040f24468be8
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-19 00:34:52 +00:00
co-authored by renee-png
+9 -7
View File
@@ -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<Row & { id: string }> = 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[]));
}
}
}