From 4441d0f089e8a5ade7a84646ebdc1a7731ba0548 Mon Sep 17 00:00:00 2001 From: 732642856 <732642856@qq.com> Date: Mon, 20 Jul 2026 17:56:28 +0800 Subject: [PATCH] fix: report missing chart profile deletes --- frontend/src/app/api/chart-profiles/[id]/route.ts | 7 +++++-- tests/test_supabase_user_data_contract.py | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/api/chart-profiles/[id]/route.ts b/frontend/src/app/api/chart-profiles/[id]/route.ts index bc49ae14..2acce5c1 100644 --- a/frontend/src/app/api/chart-profiles/[id]/route.ts +++ b/frontend/src/app/api/chart-profiles/[id]/route.ts @@ -17,14 +17,17 @@ export async function DELETE(_request: Request, context: RouteContext) { const { data: { user } } = await supabase.auth.getUser(); if (!user) return NextResponse.json({ error: "请先登录" }, { status: 401 }); - const { error } = await supabase + const { count, error } = await supabase .from("chart_profiles") - .delete() + .delete({ count: "exact" }) .eq("id", id) .eq("user_id", user.id) .eq("role", "other"); if (error) throw error; + if (count !== 1) { + return NextResponse.json({ error: "星盘不存在或无权删除" }, { status: 404 }); + } return NextResponse.json({ ok: true }); } catch (error) { if (isSupabaseConfigurationError(error)) { diff --git a/tests/test_supabase_user_data_contract.py b/tests/test_supabase_user_data_contract.py index f45dec94..e51b43fb 100644 --- a/tests/test_supabase_user_data_contract.py +++ b/tests/test_supabase_user_data_contract.py @@ -145,7 +145,10 @@ def test_chart_profile_library_has_cloud_table_api_and_local_fallback() -> None: ): assert token in route assert 'upsert(record, { onConflict: "id" })' not in route + assert '.delete({ count: "exact" })' in delete_route assert 'eq("role", "other")' in delete_route + assert "count !== 1" in delete_route + assert "星盘不存在或无权删除" in delete_route for token in ( "fetchCloudChartLibrary",