A full-featured CRM built with React, shadcn/ui, and Supabase.
Extract delete note attachments handler from Deno.serve
Anibal Svarcasf9f836e2b70e
diff --git a/supabase/functions/delete_note_attachments/index.ts b/supabase/functions/delete_note_attachments/index.tsindex 53510d73..00a68e1e 100644--- a/supabase/functions/delete_note_attachments/index.ts+++ b/supabase/functions/delete_note_attachments/index.ts@@ -19,42 +19,44 @@ type WebhookPayload = {record?: NoteRecord | null;};-Deno.serve(async (req: Request) =>- AuthMiddleware(req, async (req: Request) => {- if (req.method !== "POST") {- return jsonResponse({ error: "Method Not Allowed" }, 405);- }-- const payload = (await req.json()) as WebhookPayload;- const paths = getPathsToDelete(payload);-- if (paths.length === 0) {- return jsonResponse({- status: "skipped",- reason: "no_paths_to_delete",- type: payload.type ?? null,- });- }-- const { error } = await supabaseAdmin.storage- .from(ATTACHMENTS_BUCKET)- .remove(paths);-- if (error) {- console.error("Failed to delete note attachments", {- type: payload.type ?? null,- paths,- error,- });- return jsonResponse({ error: "Failed to delete note attachments" }, 500);- }+const deleteNoteAttachments = async (req: Request) => {+ if (req.method !== "POST") {+ return jsonResponse({ error: "Method Not Allowed" }, 405);+ }+ const payload = (await req.json()) as WebhookPayload;+ const paths = getPathsToDelete(payload);++ if (paths.length === 0) {return jsonResponse({- status: "ok",+ status: "skipped",+ reason: "no_paths_to_delete",+ type: payload.type ?? null,+ });+ }++ const { error } = await supabaseAdmin.storage+ .from(ATTACHMENTS_BUCKET)+ .remove(paths);++ if (error) {+ console.error("Failed to delete note attachments", {type: payload.type ?? null,- deletedPathsCount: paths.length,+ paths,+ error,});- }),+ return jsonResponse({ error: "Failed to delete note attachments" }, 500);+ }++ return jsonResponse({+ status: "ok",+ type: payload.type ?? null,+ deletedPathsCount: paths.length,+ });+};++Deno.serve(async (req: Request) =>+ AuthMiddleware(req, async (req: Request) => deleteNoteAttachments(req)),);const getPathsToDelete = (payload: WebhookPayload): string[] => {