Skip to content

Commit e92d57b

Browse files
committed
address delete function review feedback
1 parent afacf4e commit e92d57b

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

supabase/functions/delete-account/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ function jsonResponse(body: Record<string, unknown>, status: number) {
1212
});
1313
}
1414

15-
function getErrorMessage(error: unknown) {
16-
return error instanceof Error ? error.message : "Unexpected error";
17-
}
18-
1915
serve(async (req) => {
2016
try {
2117
if (req.method !== "POST") {
@@ -83,7 +79,12 @@ serve(async (req) => {
8379
throw listingsError;
8480
}
8581
// Delete media for each listing
86-
for (const listing of listings) {
82+
for (const listing of listings ?? []) {
83+
if (!listing.slug) {
84+
console.warn("Skipping listing media deletion because slug is missing");
85+
continue;
86+
}
87+
8788
try {
8889
await deleteListingMedia(supabaseAdmin, listing.slug);
8990
} catch (error) {
@@ -105,6 +106,6 @@ serve(async (req) => {
105106
return jsonResponse({ success: true }, 200);
106107
} catch (error) {
107108
console.error("Final error:", error);
108-
return jsonResponse({ error: getErrorMessage(error) }, 500);
109+
return jsonResponse({ error: "Internal server error" }, 500);
109110
}
110111
});

supabase/functions/delete-listing/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ function jsonResponse(body: Record<string, unknown>, status: number) {
1010
});
1111
}
1212

13-
function getErrorMessage(error: unknown) {
14-
return error instanceof Error ? error.message : "Unexpected error";
15-
}
16-
1713
serve(async (req) => {
1814
try {
1915
if (req.method !== "POST") {
@@ -89,6 +85,6 @@ serve(async (req) => {
8985
return jsonResponse({ success: true }, 200);
9086
} catch (error) {
9187
console.error("Final error:", error);
92-
return jsonResponse({ error: getErrorMessage(error) }, 500);
88+
return jsonResponse({ error: "Internal server error" }, 500);
9389
}
9490
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- The later (thread_id, created_at desc, id desc) index covers thread message
2+
-- lookups, so this older single-column index only adds write overhead.
3+
4+
drop index if exists public.chat_messages_thread_id_idx;

0 commit comments

Comments
 (0)