fix: insert other chart profiles directly (#15)
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user