import { and, asc, eq } from "drizzle-orm"; import type { AppDatabase } from "../database-context.js"; import { buildings } from "../schema/buildings.js"; export class BuildingRepository { constructor(private readonly database: AppDatabase) {} async listByProject(projectId: string) { return this.database .select() .from(buildings) .where(eq(buildings.projectId, projectId)) .orderBy(asc(buildings.sortOrder), asc(buildings.name)); } async findById(projectId: string, buildingId: string) { return ( this.database .select() .from(buildings) .where( and(eq(buildings.projectId, projectId), eq(buildings.id, buildingId)) ) .get() ?? null ); } }