From cbf1357654e038b525d9989ca56c0700536f01c7 Mon Sep 17 00:00:00 2001 From: "open-swe-dev-andrinoid[bot]" Date: Thu, 22 Jan 2026 05:49:18 +0000 Subject: [PATCH] Apply patch [skip ci] --- routes/api/update/lease_accept.ts | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 routes/api/update/lease_accept.ts diff --git a/routes/api/update/lease_accept.ts b/routes/api/update/lease_accept.ts new file mode 100644 index 0000000..c366d18 --- /dev/null +++ b/routes/api/update/lease_accept.ts @@ -0,0 +1,50 @@ +// routes/api/update/lease_accept.ts +import { define } from "../../../utils.ts"; +import { signLease } from "../../../services/leaseService.ts"; +import { SessionCookie } from "../../auth/callback.ts"; + +export const handler = define.handlers({ + async POST(ctx) { + try { + const stateData: SessionCookie = ctx.state.data; + const { user_id } = stateData || {}; + + if (!user_id) { + return new Response(JSON.stringify({ error: "Unauthorized" }), { + status: 401, + headers: { "Content-Type": "application/json" }, + }); + } + + const contentType = ctx.req.headers.get("content-type") || ""; + let data: Record = {}; + if (contentType.includes("application/json")) { + data = await ctx.req.json(); + } else { + const form = await ctx.req.formData(); + for (const [k, v] of form.entries()) { + data[k] = typeof v === "string" ? v : String(v); + } + } + + const lease_id = (data.lease_id as string) || (data["lease_id"] as string); + if (!lease_id) { + return new Response(JSON.stringify({ error: "lease_id is required" }), { + status: 400, + headers: { "Content-Type": "application/json" }, + }); + } + + const result = await signLease(lease_id, user_id as string); + return new Response(JSON.stringify({ success: true, lease: result?.[0] || null }), { + status: 200, + headers: { "Content-Type": "application/json" }, + }); + } catch (err) { + return new Response(JSON.stringify({ error: String(err) }), { + status: 500, + headers: { "Content-Type": "application/json" }, + }); + } + }, +});