fix: insert other chart profiles directly (#15)

This commit is contained in:
732642856
2026-07-20 17:45:31 +08:00
committed by GitHub
parent cdfd389662
commit b3bca954da
4 changed files with 17 additions and 12 deletions
+1 -8
View File
@@ -70,16 +70,9 @@ export async function POST(request: Request) {
.single();
({ data, error } = await query);
} else {
const record = {
...(body.id ? { id: body.id } : {}),
user_id: user.id,
role,
profile: body.profile,
updated_at: updatedAt,
};
({ data, error } = await supabase
.from("chart_profiles")
.upsert(record, { onConflict: "id" })
.insert({ user_id: user.id, role, profile: body.profile, updated_at: updatedAt })
.select("id, role, profile, updated_at")
.single());
}
+2 -3
View File
@@ -337,13 +337,12 @@ async function saveCloudChartProfile(record: ChartLibraryRecord) {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: record.role === "self" ? undefined : record.id,
role: record.role,
profile: record.profile,
}),
});
if (!response.ok) throw new Error("cloud_chart_profile_save_failed");
const payload = await response.json().catch(() => null) as { profile?: ChartLibraryApiRecord } | null;
const payload = await response.json().catch(() => null) as { profile?: ChartLibraryApiRecord; error?: string } | null;
if (!response.ok) throw new Error(payload?.error || "cloud_chart_profile_save_failed");
return payload?.profile ? normalizeChartLibraryApiRecord(payload.profile) : record;
}