// routes/api/delete/lease.ts import { deleteObligation } from "../../../services/financhalServices.ts"; import { define } from "../../../utils.ts"; import { SessionCookie } from "../../auth/callback.ts"; export const handler = define.handlers({ async POST(ctx) { const formData = await ctx.req.formData(); const obligation_id = formData.get("obligation_id"); const sender = formData.get("sender"); if (!obligation_id || !sender) { return new Response("Missing obligation_id or sender", { status: 400 }); } // Delete the obligation using your service function await deleteObligation(obligation_id.toString()); // Redirect back to the sender URL (must be absolute) const senderPath = sender.toString(); let redirectUrl = senderPath; try { if (senderPath.startsWith("/")) { const url = new URL(ctx.req.url); redirectUrl = url.origin + senderPath; } } catch (_) { // fallback: just use senderPath } return Response.redirect(redirectUrl, 303); }, });