fix: add missing signLease function and fix type errors in leaseService (#124)

* Apply patch [skip ci]

* Apply patch [skip ci]

* Apply patch [skip ci]

* Empty commit to trigger CI

---------

Co-authored-by: open-swe-dev-andrinoid[bot] <open-swe-dev-andrinoid@users.noreply.github.com>
This commit is contained in:
open-swe-dev-andrinoid[bot] 2026-01-28 14:18:29 -06:00 committed by GitHub
parent 577a7e8c68
commit cdc6e49414
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 4 deletions

1
db/schema.ts Executable file → Normal file
View File

@ -241,6 +241,7 @@ export const tenant_invites = pgTable("tenant_invites", {
id: text("id").primaryKey(),
landlord_id: text("landlord_id").references(() => users.id),
property_id: text("property_id").references(() => properties.id),
lease_id: text("lease_id").references(() => leases.id),
available_on: bigint("available_on", { mode: "number" }),
invited_emails: text("invited_emails"), // JSON array of invited emails
created_on: bigint("created_on", { mode: "number" }),

View File

@ -233,6 +233,18 @@ export async function deleteLease(id: string) {
.returning();
}
// Sign lease document
export async function signLease(lease_id: string, user_id: string) {
const now = Date.now();
return await db.update(leases)
.set({
lease_document_url: `signed_${lease_id}_${now}`,
updated_on: now,
})
.where(eq(leases.id, lease_id))
.returning();
}
// Get lease statistics for an owner
export async function getLeaseStatsByOwner(owner_id: string) {
const allLeases = await getLeasesByOwner(owner_id);
@ -268,10 +280,17 @@ export async function inviteLease(lease_id: string, inviteId?: string) {
const lease = await getLeaseById(lease_id);
if (!lease) return null;
const property_id = lease.property_id;
const landlord_id = lease.owner_id;
if (!property_id || !landlord_id) {
return null;
}
const existing = await db.select().from(tenant_invites).where(
and(
eq(tenant_invites.property_id, lease.property_id),
eq(tenant_invites.landlord_id, lease.owner_id),
eq(tenant_invites.property_id, property_id),
eq(tenant_invites.landlord_id, landlord_id),
),
);
@ -286,8 +305,8 @@ export async function inviteLease(lease_id: string, inviteId?: string) {
// Create a new invite linking to this lease
return await db.insert(tenant_invites).values({
id: crypto.randomUUID(),
landlord_id: lease.owner_id,
property_id: lease.property_id,
landlord_id,
property_id,
lease_id,
available_on: null,
invited_emails: JSON.stringify([]),