Merge pull request #50 from nathanAndrinoid/open-swe/06957287-568f-4d29-b7a6-10c33ed95d98

[WIP]: Implement Lease Creation UI & Tenant Accept Endpoint; Fix Payment/TS Handler Types
This commit is contained in:
nathanAndrinoid 2026-01-22 10:55:13 -06:00 committed by GitHub
commit c6f6149e62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 141 additions and 0 deletions

View File

@ -0,0 +1,54 @@
// 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<string, unknown> = {};
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" },
});
}
},
});

View File

@ -0,0 +1,67 @@
// routes/api/update/lease_invite.ts
import { define } from "../../../utils.ts";
import { getLeaseById } from "../../../services/leaseService.ts";
import { createTenantInvite } from "../../../services/tenantInviteService.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<string, unknown> = {};
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 lease = await getLeaseById(lease_id);
if (!lease) {
return new Response(JSON.stringify({ error: "lease not found" }), {
status: 404,
headers: { "Content-Type": "application/json" },
});
}
const property_id = lease.property_id as string | undefined;
if (!property_id) {
return new Response(JSON.stringify({ error: "lease has no property_id" }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
}
const invite = await createTenantInvite(user_id as string, property_id);
return new Response(JSON.stringify({ success: true, invite }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
} catch (err) {
return new Response(JSON.stringify({ error: String(err) }), {
status: 500,
headers: { "Content-Type": "application/json" },
});
}
},
});

View File

@ -536,3 +536,20 @@ export default define.page(
); );
}, },
); );

View File

@ -282,3 +282,4 @@ export default define.page(function LandlordPayments({ data }) {
</div> </div>
); );
}); });

View File

@ -171,3 +171,4 @@ export default define.page(function LandlordPortfolio({ data }) {
</div> </div>
); );
}); });

View File

@ -536,3 +536,4 @@ export default define.page(function LandlordPropertyCleanup({ data }) {
</div> </div>
); );
}); });