// routes/landlord/properties/index.tsx import { define } from "../../../utils.ts"; import { SessionCookie } from "../../auth/callback.ts"; import { getPropertiesByUser } from "../../../services/propertyService.ts"; import { page } from "fresh"; import { Property } from "../../../db/interfaces.ts"; export const handler = define.handlers({ async GET(ctx) { const stateData: SessionCookie = ctx.state.data; const { user_id } = stateData; if (!user_id) { return new Response("", { status: 302, headers: { Location: "/auth/login" }, }); } try { const properties = await getPropertiesByUser(user_id); return page({ stateData, properties, }); } catch (error) { console.error("Error loading properties:", error); return page({ stateData, error: "Failed to load properties", }); } }, }); export default define.page(function LandlordProperties({ data }) { const { stateData, properties, error } = data as { stateData: SessionCookie; properties: Property[]; error?: string; }; return (
Manage your rental properties and listings
{property.city}, {property.state} {property.zip}
{property.bedrooms} bed • {property.bathrooms} bath {property.square_footage && ` • ${property.square_footage.toLocaleString()} sq ft`}
${property.monthly_rent?.toLocaleString() || "N/A"}/month